diff --git a/includes/migration/dotnet-v7/enablelogs-is-removed-from-sentryoptions.mdx b/includes/migration/dotnet-v7/enablelogs-is-removed-from-sentryoptions.mdx index 5772557c4f264..ea37d0c88f393 100644 --- a/includes/migration/dotnet-v7/enablelogs-is-removed-from-sentryoptions.mdx +++ b/includes/migration/dotnet-v7/enablelogs-is-removed-from-sentryoptions.mdx @@ -13,7 +13,7 @@ Version 7 removes `EnableLogs` from `SentryOptions`, the core options of the SDK Whether logs are on now depends on how your app writes them: -- **Logging integrations.** If you add the Serilog, NLog or log4net integration, or call `Logging.AddSentry()` after `SentrySdk.Init`, logs are on by default. Your logging framework's configuration, such as its minimum level, controls which entries they send. See [Logging Integrations Send Logs](#logging-integrations-send-logs). +- **Logging integrations.** If you add the Serilog, NLog or log4net integration, or call `Logging.AddSentry()` after `SentrySdk.Init`, logs are on by default. Your logging framework's configuration, such as its minimum level, controls which entries they send. To turn off the logs from `Logging.AddSentry()` and keep its errors and breadcrumbs, set `Logging:Sentry:LogLevel:Default` to `None`. See [Logging Integrations Send Logs](#logging-integrations-send-logs). - **Host integrations.** In ASP.NET Core, MAUI, Blazor WebAssembly and generic host apps, `UseSentry` adds an `ILogger` integration. It sends errors and breadcrumbs, but its logs are off by default. To turn them on, set `EnableLogs = true` on the options of `UseSentry`. `EnableLogs` doesn't affect a Serilog, NLog or log4net integration in the same app. - **`SentrySdk.Logger`.** It sends logs in every app and needs no option. diff --git a/includes/migration/dotnet-v7/logging-integrations-send-logs.mdx b/includes/migration/dotnet-v7/logging-integrations-send-logs.mdx index ba6bf246ed2b8..f3f52ac537c45 100644 --- a/includes/migration/dotnet-v7/logging-integrations-send-logs.mdx +++ b/includes/migration/dotnet-v7/logging-integrations-send-logs.mdx @@ -32,7 +32,14 @@ SentrySdk.Init(options => }); ``` -To drop every log and keep sending errors and breadcrumbs, return `null`: +To drop every log and keep sending errors and breadcrumbs, return `null` from `SetBeforeSendLog`. The callback works for every integration and for `SentrySdk.Logger`. Some integrations also have their own switch, which you can set in configuration and which stops the SDK from creating those logs at all: + +- For `ILogger`, turn off the `Sentry` logging provider, as shown below. +- For NLog, set [`minimumLogLevel`](/platforms/dotnet/guides/nlog/logs/#minimumloglevel) to `Off` on the target. + +The Serilog sink and the log4net appender have no such switch, so use the callback for those. + +With the callback, return `null`: ```csharp {filename:Program.cs} SentrySdk.Init(options => @@ -42,7 +49,7 @@ SentrySdk.Init(options => }); ``` -In apps that call `UseSentry`, set the same callback on its options. The callback applies to every log, including logs from `SentrySdk.Logger` and from the `ILogger` integration. +In apps that call `UseSentry`, set the same callback on its options: ```csharp {filename:Program.cs} var builder = WebApplication.CreateBuilder(args); @@ -53,4 +60,29 @@ builder.UseSentry(options => }); ``` -See [Logs](/platforms/dotnet/logs/) for more about filtering logs. +To turn off the `Sentry` logging provider, set its level to `None`. If your app reads the `Logging` section from configuration, as `WebApplication.CreateBuilder` and `Host.CreateApplicationBuilder` do, set it in `appsettings.json`: + +```json {filename:appsettings.json} +{ + "Logging": { + "Sentry": { + "LogLevel": { + "Default": "None" + } + } + } +} +``` + +Otherwise, add the same rule when you add the integration: + +```csharp {filename:Program.cs} +using var loggerFactory = LoggerFactory.Create(builder => +{ + builder.AddSentry(); + builder.Services.Configure(options => + options.Rules.Add(new LoggerFilterRule("Sentry", null, LogLevel.None, null))); +}); +``` + +See [Logs](/platforms/dotnet/logs/) for more about filtering logs, and [Configure Microsoft.Extensions.Logging Filters](/platforms/dotnet/guides/extensions-logging/logs/#configure-microsoftextensionslogging-filters) for more about the `Sentry` provider. diff --git a/platform-includes/logs/options/dotnet.mdx b/platform-includes/logs/options/dotnet.mdx index 8801a6d9f9e33..481c82ab541c8 100644 --- a/platform-includes/logs/options/dotnet.mdx +++ b/platform-includes/logs/options/dotnet.mdx @@ -18,7 +18,7 @@ In earlier versions, `EnableLogs` was an option on `SentryOptions`, and the Seri #### Configure Microsoft.Extensions.Logging Filters -Sentry's `Microsoft.Extensions.Logging` provider defines the alias `Sentry`. +Sentry's `Microsoft.Extensions.Logging` provider defines the alias `Sentry`, so you can use `Sentry` as the provider name in your filters. A `LogLevel` section under `Logging:Sentry` applies only to the logs Sentry sends. Its keys are categories, the same as in the top-level `LogLevel` section. Logs emitted through `ILogger` are sent to Sentry according to your configured provider/category filters and log levels.