From 92714779689e991e140a7092a3381393ccc7b75a Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 16 Jul 2026 15:43:28 +1200 Subject: [PATCH 1/2] docs(dotnet): Document Serilog per-sink minimum level options Sentry.Serilog 6.8.0 adds RestrictedToMinimumLevel and LevelSwitch options so Serilog's per-sink minimum level can be configured in code. Previously this was only possible via appsettings.json, which was painful for MAUI users who configure Serilog in code. Add a section explaining how the per-sink level differs from MinimumBreadcrumbLevel/MinimumEventLevel, with code and appsettings examples, and document the two new options. Refs getsentry/sentry-dotnet#4957 Co-Authored-By: Claude --- .../platforms/dotnet/guides/serilog/index.mdx | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/docs/platforms/dotnet/guides/serilog/index.mdx b/docs/platforms/dotnet/guides/serilog/index.mdx index 260b4794ef35a..f8e238e3857a6 100644 --- a/docs/platforms/dotnet/guides/serilog/index.mdx +++ b/docs/platforms/dotnet/guides/serilog/index.mdx @@ -109,6 +109,52 @@ The SDK only needs to be initialized once. If a `DSN` is made available to this +### Filtering Which Log Events Reach Sentry + +`MinimumBreadcrumbLevel` and `MinimumEventLevel` determine what the sink does with a log event, but every log event the logger captures still reaches the sink. If your logger's minimum level is verbose — for example, because another sink writes debug logs to a file — you can use Serilog's [per-sink minimum level](https://github.com/serilog/serilog/wiki/Configuration-Basics#overriding-per-sink) to stop lower-level log events from reaching Sentry entirely. This also controls which log entries are sent to Sentry as [structured logs](logs/): + +```csharp +Log.Logger = new LoggerConfiguration() + // Debug and higher are written to the file + .MinimumLevel.Debug() + .WriteTo.File("app.log") + .WriteTo.Sentry(o => + { + // Only Warning and higher reach the Sentry sink + o.RestrictedToMinimumLevel = LogEventLevel.Warning; + o.MinimumEventLevel = LogEventLevel.Error; + }) + .CreateLogger(); +``` + +```json {filename:appsettings.json} +{ + "Serilog": { + "Using": [ "Sentry.Serilog" ], + "MinimumLevel": { + "Default": "Debug" + }, + "WriteTo": [ + { + "Name": "Sentry", + "Args": { + "minimumEventLevel": "Error", + "restrictedToMinimumLevel": "Warning" + } + } + ] + } +} +``` + +To change the sink's minimum level at runtime, set the `LevelSwitch` option to a [LoggingLevelSwitch](https://github.com/serilog/serilog/wiki/Configuration-Basics#dynamic-levels) instead. + + + +Setting the per-sink minimum level in code requires Sentry.Serilog version 6.8.0 or later. In earlier versions, it can only be set via `appsettings.json`. + + + ### Options #### MinimumBreadcrumbLevel @@ -123,6 +169,14 @@ A `LogLevel` which indicates the minimum level a log message has to be sent to S Whether or not this integration should initialize the SDK. If you intend to call `SentrySdk.Init` yourself you should set this flag to `false`. +#### RestrictedToMinimumLevel + +A `LogEventLevel` which indicates the minimum level a log event has to be processed by the sink at all. By default this value is `Verbose`, meaning no log events are filtered out. Ignored when `LevelSwitch` is set. + +#### LevelSwitch + +An optional `LoggingLevelSwitch` that allows the sink's minimum level to be changed at runtime. + ## Verify This snippet includes an intentional error, so you can test that everything is working as soon as you set it up. From 0e5763946c0740544caa5c445e03a8734cd5409f Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Fri, 17 Jul 2026 14:56:58 +1200 Subject: [PATCH 2/2] Consolidate to a more concise explanation Co-authored-by: James Crosswell --- .../platforms/dotnet/guides/serilog/index.mdx | 56 +++---------------- 1 file changed, 9 insertions(+), 47 deletions(-) diff --git a/docs/platforms/dotnet/guides/serilog/index.mdx b/docs/platforms/dotnet/guides/serilog/index.mdx index f8e238e3857a6..3b2f31a37737d 100644 --- a/docs/platforms/dotnet/guides/serilog/index.mdx +++ b/docs/platforms/dotnet/guides/serilog/index.mdx @@ -109,52 +109,6 @@ The SDK only needs to be initialized once. If a `DSN` is made available to this -### Filtering Which Log Events Reach Sentry - -`MinimumBreadcrumbLevel` and `MinimumEventLevel` determine what the sink does with a log event, but every log event the logger captures still reaches the sink. If your logger's minimum level is verbose — for example, because another sink writes debug logs to a file — you can use Serilog's [per-sink minimum level](https://github.com/serilog/serilog/wiki/Configuration-Basics#overriding-per-sink) to stop lower-level log events from reaching Sentry entirely. This also controls which log entries are sent to Sentry as [structured logs](logs/): - -```csharp -Log.Logger = new LoggerConfiguration() - // Debug and higher are written to the file - .MinimumLevel.Debug() - .WriteTo.File("app.log") - .WriteTo.Sentry(o => - { - // Only Warning and higher reach the Sentry sink - o.RestrictedToMinimumLevel = LogEventLevel.Warning; - o.MinimumEventLevel = LogEventLevel.Error; - }) - .CreateLogger(); -``` - -```json {filename:appsettings.json} -{ - "Serilog": { - "Using": [ "Sentry.Serilog" ], - "MinimumLevel": { - "Default": "Debug" - }, - "WriteTo": [ - { - "Name": "Sentry", - "Args": { - "minimumEventLevel": "Error", - "restrictedToMinimumLevel": "Warning" - } - } - ] - } -} -``` - -To change the sink's minimum level at runtime, set the `LevelSwitch` option to a [LoggingLevelSwitch](https://github.com/serilog/serilog/wiki/Configuration-Basics#dynamic-levels) instead. - - - -Setting the per-sink minimum level in code requires Sentry.Serilog version 6.8.0 or later. In earlier versions, it can only be set via `appsettings.json`. - - - ### Options #### MinimumBreadcrumbLevel @@ -171,7 +125,15 @@ Whether or not this integration should initialize the SDK. If you intend to call #### RestrictedToMinimumLevel -A `LogEventLevel` which indicates the minimum level a log event has to be processed by the sink at all. By default this value is `Verbose`, meaning no log events are filtered out. Ignored when `LevelSwitch` is set. +`MinimumBreadcrumbLevel` and `MinimumEventLevel` determine what the sink does with a log event, but every log event the logger captures still reaches the sink. If your logger's minimum level is verbose — for example, because another sink writes debug logs to a file — you can use Serilog's [per-sink minimum level](https://github.com/serilog/serilog/wiki/Configuration-Basics#overriding-per-sink) to stop lower-level log events from reaching Sentry entirely. + +By default this value is `Verbose`, meaning no log events are filtered out. Ignored when `LevelSwitch` is set. + + + +This also controls which log entries are sent to Sentry as [structured logs](logs/) + + #### LevelSwitch