Skip to content

Commit dd39b87

Browse files
ric-olivclaude
andcommitted
docs(dotnet): Show how to turn off logs from Logging.AddSentry()
The v7 migration guide only showed SetBeforeSendLog(_ => null) for dropping logs. Apps that call SentrySdk.Init and Logging.AddSentry() can set the Sentry provider's level to None instead, which keeps errors and breadcrumbs, works from configuration and creates no logs. Refs getsentry/sentry-dotnet#5988 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8382ed7 commit dd39b87

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎includes/migration/dotnet-v7/enablelogs-is-removed-from-sentryoptions.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Version 7 removes `EnableLogs` from `SentryOptions`, the core options of the SDK
1313

1414
Whether logs are on now depends on how your app writes them:
1515

16-
- **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).
16+
- **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 `LogLevel` to `None` under `Logging:Sentry`. See [Logging Integrations Send Logs](#logging-integrations-send-logs).
1717
- **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.
1818
- **`SentrySdk.Logger`.** It sends logs in every app and needs no option.
1919

‎includes/migration/dotnet-v7/logging-integrations-send-logs.mdx‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ SentrySdk.Init(options =>
3232
});
3333
```
3434

35-
To drop every log and keep sending errors and breadcrumbs, return `null`:
35+
To drop every log and keep sending errors and breadcrumbs, return `null` from `SetBeforeSendLog`, or turn off the `Sentry` logging provider. The callback works for every integration and for `SentrySdk.Logger`. The provider setting works only for `Logging.AddSentry()`, but you can set it in configuration, and the SDK creates no logs for the entries it filters.
36+
37+
With the callback, return `null`:
3638

3739
```csharp {filename:Program.cs}
3840
SentrySdk.Init(options =>
@@ -42,7 +44,7 @@ SentrySdk.Init(options =>
4244
});
4345
```
4446

45-
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.
47+
In apps that call `UseSentry`, set the same callback on its options:
4648

4749
```csharp {filename:Program.cs}
4850
var builder = WebApplication.CreateBuilder(args);
@@ -53,4 +55,29 @@ builder.UseSentry(options =>
5355
});
5456
```
5557

58+
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`:
59+
60+
```json {filename:appsettings.json}
61+
{
62+
"Logging": {
63+
"Sentry": {
64+
"LogLevel": {
65+
"Default": "None"
66+
}
67+
}
68+
}
69+
}
70+
```
71+
72+
Otherwise, add the same rule when you add the integration:
73+
74+
```csharp {filename:Program.cs}
75+
using var loggerFactory = LoggerFactory.Create(builder =>
76+
{
77+
builder.AddSentry();
78+
builder.Services.Configure<LoggerFilterOptions>(options =>
79+
options.Rules.Add(new LoggerFilterRule("Sentry", null, LogLevel.None, null)));
80+
});
81+
```
82+
5683
See [Logs](/platforms/dotnet/logs/) for more about filtering logs.

0 commit comments

Comments
 (0)