From b53cfe09e336a9fe0fa38d4b5ced9ed20fec7e62 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 26 Feb 2026 14:34:00 +1300 Subject: [PATCH 1/2] Explain how to configure filters for structured logs resolves https://github.com/getsentry/sentry-dotnet/issues/4952#issuecomment-3954373997 --- .../guides/extensions-logging/index.mdx | 18 ++++++--- .../platforms/dotnet/guides/serilog/index.mdx | 40 ++++++++++++++++++- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/docs/platforms/dotnet/guides/extensions-logging/index.mdx b/docs/platforms/dotnet/guides/extensions-logging/index.mdx index 54e397b2a4290f..a45cde0a45c698 100644 --- a/docs/platforms/dotnet/guides/extensions-logging/index.mdx +++ b/docs/platforms/dotnet/guides/extensions-logging/index.mdx @@ -18,9 +18,9 @@ By default, any message with log level `Information` or higher will be kept as a The default value to report a log entry as an event to Sentry is `Error`. -This means that out of the box, any `LogError` call will create an `Event` which will include all log messages of level `Information`, `Warning` and also `Error` and `Critical`. +This means that out of the box, any `LogError` call will create an `Event` which will include breadcrumbs for all prior log messages of level `Information`, `Warning`, `Error` and `Critical`. -Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). +Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). Filtering to control the minimum log level to capture should be done [via `Microsoft.Extensions.Logging` configuration](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging/overview?tabs=command-line#how-filtering-rules-are-applied). ## Install @@ -89,7 +89,8 @@ Example using `appsettings.json`: { "Logging": { "LogLevel": { - "Default": "Debug" + "Default": "Debug", + "Microsoft": "Warning" } }, "Sentry": { @@ -102,7 +103,7 @@ Example using `appsettings.json`: } ``` -Above we set the application wide minimum log level to `Debug`. Sentry specific settings are set under the `Sentry` property. Options are documented below. +Above we set the application wide minimum log level to `Debug` and we configure a minimum log level for Microsoft specific logs to `Warning`. Sentry specific settings are set under the `Sentry` property. Options are documented below. #### Through `ILoggerFactory` @@ -117,6 +118,7 @@ using (var loggerFactory = new LoggerFactory() ``` This approach doesn't include any of the framework's configuration system. Since the DSN is being provided via parameter, the SDK will be initialized. + More settings can be passed via the callback configuring the `SentryOptions`. ## Options and Initialization @@ -153,7 +155,13 @@ Whether or not this integration should initialize the SDK. If you intend to call #### Filters -A list of filters which are invoked before processing any log message. This allows you to inspect the details of the log entry before they become a `Breadcrumb` or an `Event` with full access to the `Microsoft.Extensions.Logging` data. +A list of filters which are invoked before processing log messages. This allows you to inspect the details of the log entry before they become a `Breadcrumb` or an `Event` with full access to the `Microsoft.Extensions.Logging` data. + + + +These filters only apply to breadcrumbs and events. They don't control which logs will be captured as structured logs in Sentry. That can be controlled independently using the [filtering capabilities built into `Microsoft.Extensions.Logging`](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging/overview?tabs=command-line#how-filtering-rules-are-applied). + + #### TagFilters diff --git a/docs/platforms/dotnet/guides/serilog/index.mdx b/docs/platforms/dotnet/guides/serilog/index.mdx index 767c129dc6ecd9..fb736f7587121b 100644 --- a/docs/platforms/dotnet/guides/serilog/index.mdx +++ b/docs/platforms/dotnet/guides/serilog/index.mdx @@ -18,9 +18,9 @@ By default, any message with log level `Information` or higher will be kept as a The default value to report a log entry as an event to Sentry is `Error`. -This means that out of the box, any `LogError` call will create an `Event` which will include all log messages of level `Information`, `Warning` and also `Error` and `Critical`. +This means that out of the box, any `LogError` call will create an `Event` which will include breadcrumbs for all prior log messages of level `Information`, `Warning`, `Error` and `Critical`. -Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). +Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). You can control which logs captured using the [Serilog MinimumLogLevel](https://github.com/serilog/serilog/wiki/Configuration-Basics#minimum-level). ## Install @@ -58,6 +58,26 @@ Log.Logger = new LoggerConfiguration() .CreateLogger(); ``` +```appsettings.json +{ + "Serilog": { + "Using": [ "Sentry.Serilog" ], + "MinimumLevel": { + "Default": "Debug" + }, + "WriteTo": [ + { + "Name": "Sentry", + "Args": { + "minimumBreadcrumbLevel": "Debug", + "minimumEventLevel": "Warning" + } + } + ] + } +} +``` + It's also possible to initialize the SDK through the Serilog integration. This is useful when the Serilog is the only integration being used in your application. To initialize the Sentry SDK through the Serilog integration, provide it with the DSN: @@ -67,6 +87,22 @@ Log.Logger = new LoggerConfiguration() .CreateLogger(); ``` +```appsettings.json +{ + "Serilog": { + "Using": [ "Sentry.Serilog" ], + "WriteTo": [ + { + "Name": "Sentry", + "Args": { + "dsn": "___PUBLIC_DSN___" + } + } + ] + } +} +``` + The SDK only needs to be initialized once. If a `DSN` is made available to this integration, by default it **will** initialize the SDK. If you do not wish to initialize the SDK via this integration, set the `InitializeSdk` flag to **false**. Not providing a DSN or leaving it as `null` instructs the integration not to initialize the SDK and unless another integration initializes it or you call `SentrySdk.Init`, the SDK will stay disabled. From 6c02dd03fa51a5650fa3b368152ecbec623427f5 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Fri, 27 Feb 2026 09:39:10 +1300 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docs/platforms/dotnet/guides/serilog/index.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/platforms/dotnet/guides/serilog/index.mdx b/docs/platforms/dotnet/guides/serilog/index.mdx index fb736f7587121b..260b4794ef35ae 100644 --- a/docs/platforms/dotnet/guides/serilog/index.mdx +++ b/docs/platforms/dotnet/guides/serilog/index.mdx @@ -20,7 +20,7 @@ The default value to report a log entry as an event to Sentry is `Error`. This means that out of the box, any `LogError` call will create an `Event` which will include breadcrumbs for all prior log messages of level `Information`, `Warning`, `Error` and `Critical`. -Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). You can control which logs captured using the [Serilog MinimumLogLevel](https://github.com/serilog/serilog/wiki/Configuration-Basics#minimum-level). +Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). You can control which logs are captured using the [Serilog MinimumLogLevel](https://github.com/serilog/serilog/wiki/Configuration-Basics#minimum-level). ## Install @@ -58,7 +58,7 @@ Log.Logger = new LoggerConfiguration() .CreateLogger(); ``` -```appsettings.json +```json {filename:appsettings.json} { "Serilog": { "Using": [ "Sentry.Serilog" ], @@ -87,7 +87,7 @@ Log.Logger = new LoggerConfiguration() .CreateLogger(); ``` -```appsettings.json +```json {filename:appsettings.json} { "Serilog": { "Using": [ "Sentry.Serilog" ],