From 0b6992d80fd188fe3b8b816f15a49619867eaf8f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 22 Aug 2022 17:12:11 -0500 Subject: reorder share scan state handling --- src/slskd/Application.cs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index f9cb95d2..5a56e110 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -927,23 +927,15 @@ namespace slskd if (!previous.Scanning && current.Scanning) { + // the scan is starting SharesRefreshStarted = DateTime.UtcNow; State.SetValue(s => s with { Shares = current }); Log.Information("Scanning shares"); } - - var lastProgress = Math.Round(previous.ScanProgress * 100); - var currentProgress = Math.Round(current.ScanProgress * 100); - - if (lastProgress != currentProgress && Math.Round(currentProgress, 0) % 10 == 0) - { - State.SetValue(s => s with { Shares = current }); - Log.Information("Scanned {Percent}% of shared directories. Found {Files} files so far.", currentProgress, current.Files); - } - - if (previous.Scanning && !current.Scanning) + else if (previous.Scanning && !current.Scanning) { + // the scan is finishing State.SetValue(s => s with { Shares = current }); if (current.Faulted) @@ -967,6 +959,18 @@ namespace slskd } } } + else + { + // the scan is neither starting nor finishing; progress update + var lastProgress = Math.Round(previous.ScanProgress * 100); + var currentProgress = Math.Round(current.ScanProgress * 100); + + if (lastProgress != currentProgress && Math.Round(currentProgress, 0) % 10d == 0) + { + State.SetValue(s => s with { Shares = current }); + Log.Information("Scanned {Percent}% () of shared directories. Found {Files} files so far.", currentProgress, current.Files); + } + } } private void State_OnChange((State Previous, State Current) state) -- cgit v1.2.3 From e319e32ef9ba22c85a85d6872ed7bdbbce04747d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 22 Aug 2022 17:38:17 -0500 Subject: include exception with logs --- src/slskd/Program.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index c8a5efe0..f9294208 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -762,13 +762,20 @@ namespace slskd { try { + var message = logEvent.RenderMessage(); + + if (logEvent.Exception != null) + { + message = $"{message}: {logEvent.Exception}"; + } + var record = new LogRecord() { Timestamp = logEvent.Timestamp.LocalDateTime, Context = logEvent.Properties["SourceContext"].ToString().TrimStart('"').TrimEnd('"'), SubContext = logEvent.Properties.ContainsKey("SubContext") ? logEvent.Properties["SubContext"].ToString().TrimStart('"').TrimEnd('"') : null, Level = logEvent.Level.ToString(), - Message = logEvent.RenderMessage().TrimStart('"').TrimEnd('"'), + Message = message.TrimStart('"').TrimEnd('"'), }; LogBuffer.Enqueue(record); -- cgit v1.2.3