aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-08-22 17:46:21 -0500
committerGitHub <noreply@github.com>2022-08-22 17:46:21 -0500
commit43b5411cbd8d85a338acc0033cfade3c509bf1f4 (patch)
treecd57348d6ef64036bb8d1f2603118eec07e07c0c /src
parent686717cfaafdcfddae9733f2ebdae178aa3fa8c0 (diff)
parente319e32ef9ba22c85a85d6872ed7bdbbce04747d (diff)
downloadslskd-43b5411cbd8d85a338acc0033cfade3c509bf1f4.tar.gz
Merge pull request #611 from slskd/share-ex
Include Exception when formatting logs
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application.cs26
-rw-r--r--src/slskd/Program.cs9
2 files changed, 23 insertions, 12 deletions
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)
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);