aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-11-22 17:40:11 -0600
committerGitHub <noreply@github.com>2025-11-22 17:40:11 -0600
commit0b15b5881e7216937530e1f19adac24d371bbf72 (patch)
tree3a4847817be5f0173e124b01acba83ef35940400 /src
parent4cbf823f928ef5b1445ca2d79684a71b69a05f43 (diff)
parent8b6a9a3108a20b280f2891e47d30ecb931d9a435 (diff)
downloadslskd-0b15b5881e7216937530e1f19adac24d371bbf72.tar.gz
Merge pull request #1538 from slskd/warnings
Add flag to enable logging of unobserved exceptions
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Options.cs9
-rw-r--r--src/slskd/Program.cs15
2 files changed, 18 insertions, 6 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 61e2878c..ec94afcb 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -418,6 +418,15 @@ namespace slskd
public bool LogSQL { get; init; } = false;
/// <summary>
+ /// Gets a value indicating whether to log unobserved Exceptions.
+ /// </summary>
+ [Argument(default, "log-unobserved-exceptions")]
+ [EnvironmentVariable("LOG_UNOBSERVED_EXCEPTIONS")]
+ [Description("log unobserved exceptions (caution: verbose)")]
+ [RequiresRestart]
+ public bool LogUnobservedExceptions { get; init; } = false;
+
+ /// <summary>
/// Gets a value indicating whether the application should run in experimental mode.
/// </summary>
[Argument(default, "experimental")]
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index ee9e2d0c..07d08fca 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -1143,12 +1143,15 @@ namespace slskd
}))
.CreateLogger();
- // // occurs when a faulted task's unobserved exception is about to trigger exception escalation policy, which, by default, would terminate the process.
- // TaskScheduler.UnobservedTaskException += (sender, e) =>
- // {
- // Serilog.Log.Logger.Error(e.Exception, "Unobserved exception: {Message}", e.Exception.Message);
- // e.SetObserved();
- // };
+ if (OptionsAtStartup.Flags.LogUnobservedExceptions)
+ {
+ // log Exceptions raised on fired-and-forgotten tasks, which adds very little value but might help debug someday
+ TaskScheduler.UnobservedTaskException += (sender, e) =>
+ {
+ Serilog.Log.Logger.Error(e.Exception, "Unobserved exception: {Message}", e.Exception.Message);
+ e.SetObserved();
+ };
+ }
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{