Skip to content

Commit 3f0e04d

Browse files
author
Nick Daniels
committed
FIX: Logs never load in viewer on first run
1 parent 267762e commit 3f0e04d

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Nabu.NetSim.UI/Services/LogService.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ public async void Tail(string path, CancellationToken cancellation)
2525
{
2626
LogEntries.Clear();
2727
var logs = new DirectoryInfo(path).GetFiles("*.log").OrderByDescending(f => f.CreationTime);
28-
29-
var current = logs.FirstOrDefault();
28+
29+
var current = logs.FirstOrDefault()?.FullName ?? Path.Combine(path, "current.log");
3030
var last = logs.Skip(1).Reverse();
3131

32-
if (current is null)
33-
return;
32+
3433
foreach (var l in last) { var loaded = false; while (!loaded) try { foreach (var line in File.ReadLines(l.FullName))
35-
LogEntries.Insert(0, line); loaded = true; } catch {} } if (LogEntries.Count > Settings.MaxLogEntries) { DropLast(Settings.MaxLogEntries); } long position = await ReadAll(current.FullName, 0, cancellation); while (!cancellation.IsCancellationRequested) {
34+
LogEntries.Insert(0, line); loaded = true; } catch {} } if (LogEntries.Count > Settings.MaxLogEntries) { DropLast(Settings.MaxLogEntries); } long position = 0; while (position == 0) try { position = await ReadAll(current, 0, cancellation); await Task.Delay(1000, cancellation); } catch { } while (!cancellation.IsCancellationRequested) {
3635
try
37-
{ position = await Read(current.FullName, position, cancellation); await Task.Delay(1000, cancellation); }
36+
{ position = await Read(current, position, cancellation); await Task.Delay(1000, cancellation); }
3837
catch { } //(Exception ex) when (ex is ArgumentOutOfRangeException or IOException) //{ // position = 0; //}
3938
}
4039

0 commit comments

Comments
 (0)