diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-11-22 17:40:11 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-22 17:40:11 -0600 |
| commit | 0b15b5881e7216937530e1f19adac24d371bbf72 (patch) | |
| tree | 3a4847817be5f0173e124b01acba83ef35940400 | |
| parent | 4cbf823f928ef5b1445ca2d79684a71b69a05f43 (diff) | |
| parent | 8b6a9a3108a20b280f2891e47d30ecb931d9a435 (diff) | |
| download | slskd-0b15b5881e7216937530e1f19adac24d371bbf72.tar.gz | |
Merge pull request #1538 from slskd/warnings
Add flag to enable logging of unobserved exceptions
| -rw-r--r-- | config/slskd.example.yml | 1 | ||||
| -rw-r--r-- | docs/config.md | 1 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 9 | ||||
| -rw-r--r-- | src/slskd/Program.cs | 15 |
4 files changed, 20 insertions, 6 deletions
diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 419c0c9f..a0ca4f3f 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -13,6 +13,7 @@ # force_migrations: false # no_version_check: false # log_sql: false +# log_unobserved_exceptions: false # experimental: false # volatile: false # case_sensitive_reg_ex: false diff --git a/docs/config.md b/docs/config.md index 5a4d3155..2646dd94 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1266,6 +1266,7 @@ Several additional feature flags are provided to change the application's runtim | `--force-migrations` | `SLSKD_FORCE_MIGRATIONS` | Force database migrations to be applied on startup | | `--no-version-check` | `SLSKD_NO_VERSION_CHECK` | Don't perform a version check on startup | | `--log-sql` | `SLSKD_LOG_SQL` | Log SQL queries generated by Entity Framework | +| `--log-unobserved-exceptions` | `SLSKD_LOG_UNOBSERVED_EXCEPTIONS` | Log unobserved Exceptions (caution: verbose) | | `--volatile` | `SLSKD_VOLATILE` | Use volatile data storage (all data will be lost at shutdown) | | `--case-sensitive-regex` | `SLSKD_CASE_SENSITIVE_REGEX` | User-defined regular expressions are case sensitive | | `--legacy-windows-tcp-keepalive` | `SLSKD_LEGACY_WINDOWS_TCP_KEEPALIVE` | Use a legacy TCP keepalive strategy for older Windows versions | 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) => { |
