Skip to content

Commit d4eb5f8

Browse files
ric-olivclaude
andcommitted
docs(dotnet): Bring the v7 migration guide up to date for rc.2
getsentry/sentry-dotnet#5755 closed without moving the ILogger integration out of UseSentry, so EnableLogs stays on the host options. Logging.AddSentry() can now add Sentry's logger providers back after ClearProviders(), and DecompressionMethods no longer includes Brotli. Rewrite the EnableLogs section around what turns logs on in each kind of app, update the ClearProviders and redundant AddSentry advice, and add an item for the Brotli default. Sum up the Serilog, NLog and log4net setups in the guide, so it doesn't depend on #19925 merging first. The release candidate note lists the two places where rc.2 still differs. Refs NET-860 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 26cdca3 commit d4eb5f8

9 files changed

Lines changed: 105 additions & 54 deletions

‎docs/platforms/dotnet/common/migration/v6-to-v7/index.mdx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ The [Interactive 7.x Migration Guide](./interactive/) lets you check off complet
6262

6363
## Logs and Metrics
6464

65-
### EnableLogs Moves to Host Options
65+
### EnableLogs Is Removed from SentryOptions
6666

67-
<Include name="migration/dotnet-v7/enablelogs-moves-to-host-options" />
67+
<Include name="migration/dotnet-v7/enablelogs-is-removed-from-sentryoptions" />
6868

6969
### Logging Integrations Send Logs
7070

@@ -102,6 +102,12 @@ The [Interactive 7.x Migration Guide](./interactive/) lets you check off complet
102102

103103
<Include name="migration/dotnet-v7/sdk-name-release-and-scope-environment" />
104104

105+
## Requests to Sentry
106+
107+
### DecompressionMethods No Longer Includes Brotli
108+
109+
<Include name="migration/dotnet-v7/decompressionmethods-no-longer-includes-brotli" />
110+
105111
## Integrations
106112

107113
### UseSentry Overrides appsettings.json in MAUI

‎includes/dotnet-v7-migration-overview.mdx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
There is no stable 7.0 release of the Sentry SDK for .NET yet. The current release candidate is `7.0.0-rc.2`. Until 7.0.0 ships, use that version wherever this guide says `7.0.0`. The rest of the .NET docs still describe 6.x until then, so where they differ from this guide, follow this guide. If you run into problems, [open an issue on GitHub](https://github.com/getsentry/sentry-dotnet/issues).
44

5+
On `7.0.0-rc.2`, two things work differently from what this guide describes:
6+
7+
- `Logging.AddSentry()` after `ClearProviders()` doesn't add Sentry's logger providers back. Call `UseSentry` after `ClearProviders()` instead.
8+
- An ASP.NET Core app that sends `ILogger` entries through NLog crashes with a stack overflow when `Debug` is on. In these apps, leave `Debug` off and check that the test event arrives in Sentry instead.
9+
510
The release candidate's `net11.0` builds depend on the .NET 11 release candidate versions of `Microsoft.Extensions.Http`, `Microsoft.Extensions.Logging.Configuration` and `Microsoft.Extensions.Configuration.Binder`. A .NET 11 app that references 10.0.x of one of these packages directly fails to restore with error NU1605. Remove that reference, or update it to the same .NET 11 release candidate version.
611

712
</Alert>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
id: decompressionmethods-no-longer-includes-brotli
3+
title: "DecompressionMethods No Longer Includes Brotli"
4+
phase: verify
5+
category: behavior
6+
severity: informational
7+
frameworks: all
8+
platformCategory: all
9+
order: 80
10+
---
11+
12+
`SentryOptions.DecompressionMethods` now defaults to `GZip | Deflate`. In 6.x, it included every method, so the SDK asked your Sentry server for Brotli-compressed responses and decoded them. Sentry's responses to the SDK are small, so this shouldn't make a visible difference.
13+
14+
The new default keeps the SDK away from the .NET Brotli decoder, which has a security issue in unpatched runtimes. See [CVE-2026-111497](https://github.com/dotnet/announcements/issues/494). This matters most for self-contained, Native AOT and mobile apps, which carry their own runtime.
15+
16+
To accept Brotli-compressed responses again, add it back. `DecompressionMethods.Brotli` is available on .NET Core 3.0 and later:
17+
18+
```csharp {filename:Program.cs}
19+
using System.Net;
20+
21+
SentrySdk.Init(options =>
22+
{
23+
options.Dsn = "___PUBLIC_DSN___";
24+
options.DecompressionMethods |= DecompressionMethods.Brotli;
25+
});
26+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
id: enablelogs-is-removed-from-sentryoptions
3+
title: "EnableLogs Is Removed from SentryOptions"
4+
phase: code-changes
5+
category: removed-api
6+
severity: action-required
7+
frameworks: all
8+
platformCategory: all
9+
order: 90
10+
---
11+
12+
Version 7 removes `EnableLogs` from `SentryOptions`, the core options of the SDK, so setting it in `SentrySdk.Init` fails to compile with error CS1061. Remove the line.
13+
14+
Whether logs are on now depends on how your app writes them:
15+
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).
17+
- **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.
18+
- **`SentrySdk.Logger`.** It sends logs in every app and needs no option.
19+
20+
In 6.x, `SentrySdk.Init` turned logs on:
21+
22+
```csharp {filename:Program.cs}
23+
SentrySdk.Init(options =>
24+
{
25+
options.Dsn = "___PUBLIC_DSN___";
26+
options.EnableLogs = true;
27+
});
28+
```
29+
30+
In 7.x, remove `EnableLogs`:
31+
32+
```csharp {filename:Program.cs}
33+
SentrySdk.Init(options =>
34+
{
35+
options.Dsn = "___PUBLIC_DSN___";
36+
});
37+
```
38+
39+
In apps that call `UseSentry`, keep `EnableLogs` on its options to send `ILogger` entries as logs. You can also set it in the `Sentry` section of `appsettings.json`:
40+
41+
```csharp {filename:Program.cs}
42+
var builder = WebApplication.CreateBuilder(args);
43+
builder.UseSentry(options =>
44+
{
45+
options.Dsn = "___PUBLIC_DSN___";
46+
options.EnableLogs = true;
47+
});
48+
```
49+
50+
A generic host app that set `EnableLogs` on `Logging.AddSentry` in 6.x sets it on `UseSentry` now.
51+
52+
The Serilog sink no longer takes an `enableLogs` argument. NLog's `enableLogs` setting no longer turns logs off, and setting it to `false` writes a warning to standard error. To drop logs and keep errors and breadcrumbs, use `SetBeforeSendLog`, as shown in [Logging Integrations Send Logs](#logging-integrations-send-logs).

‎includes/migration/dotnet-v7/enablelogs-moves-to-host-options.mdx‎

Lines changed: 0 additions & 46 deletions
This file was deleted.

‎includes/migration/dotnet-v7/generic-host-apps-call-usesentry.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ builder.Build().Run();
8787

8888
`UseSentry` also registers `IHub` for dependency injection and sets the environment from the host environment. It works on `IHostApplicationBuilder` types such as `Host.CreateApplicationBuilder` on .NET 8 and later. It also works on `IHostBuilder` types such as `Host.CreateDefaultBuilder` on every target, including .NET Framework.
8989

90-
If the app calls `builder.Logging.ClearProviders()`, call `UseSentry` after it. `ClearProviders` removes every logger provider registered before it, including Sentry's, and the app then sends no errors from `ILogger` without any warning.
90+
If the app calls `builder.Logging.ClearProviders()`, call `UseSentry` after it. `ClearProviders` removes every logger provider registered before it, including Sentry's, and the app then sends no errors from `ILogger`. If the app has to clear providers after `UseSentry`, call `builder.Logging.AddSentry()` after `ClearProviders` to add Sentry's providers back. Skip that if Serilog, NLog or log4net already sends the app's `ILogger` entries to Sentry, because each entry would then arrive twice.
9191

9292
A helper that takes any `IHostApplicationBuilder` and runs in an ASP.NET Core app, such as the `AddServiceDefaults` method of .NET Aspire, needs a different call. See [Call UseSentry on WebApplicationBuilder](#call-usesentry-on-webapplicationbuilder).
9393

94-
Like ASP.NET Core, `UseSentry` sends `ILogger` entries as logs only when you set `EnableLogs`. See [EnableLogs Moves to Host Options](#enablelogs-moves-to-host-options).
94+
Like ASP.NET Core, `UseSentry` sends `ILogger` entries as logs only when you set `EnableLogs`. See [EnableLogs Is Removed from SentryOptions](#enablelogs-is-removed-from-sentryoptions).

‎includes/migration/dotnet-v7/logging-integrations-no-longer-initialize-sentry.mdx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ Initialize Sentry with the call that matches your app:
2424

2525
`UseSentry` reads its settings from the `Sentry` section of `appsettings.json`. `SentrySdk.Init` only uses the options you set in code and environment variables such as `SENTRY_DSN`.
2626

27-
`UseSentry` also adds Sentry's own `ILogger` integration. If your app sends `ILogger` entries through Serilog, NLog or log4net, set that framework up as shown in Apps That Call UseSentry in the [Serilog](/platforms/dotnet/guides/serilog/#apps-that-call-usesentry), [NLog](/platforms/dotnet/guides/nlog/#apps-that-call-usesentry) or [log4net](/platforms/dotnet/guides/log4net/#apps-that-call-usesentry) guide, so each entry reaches Sentry once instead of twice.
27+
`UseSentry` also adds Sentry's own `ILogger` integration. If your app sends `ILogger` entries through Serilog, NLog or log4net as well, Sentry receives each entry twice unless only one of them sends it:
28+
29+
- **Serilog.** Add Serilog with `builder.Services.AddSerilog(...)` from `Serilog.Extensions.Hosting`, or with `builder.Host.UseSerilog(...)`. Both replace the app's `ILogger` factory, so each entry reaches Sentry once, through the sink. Don't use `builder.Logging.AddSerilog()` or `writeToProviders: true`.
30+
- **NLog.** Set `ReplaceLoggerFactory = true` when you add NLog, for example with `builder.Logging.AddNLog(new NLogProviderOptions { ReplaceLoggerFactory = true })`. `UseNLog` in ASP.NET Core takes the same option.
31+
- **log4net.** `AddLog4Net()` can't replace the factory. Set `MinimumEventLevel` and `MinimumBreadcrumbLevel` to `LogLevel.None` on the options of `UseSentry`, and leave `EnableLogs` off, so each entry reaches Sentry once, through the appender.
32+
33+
The [Serilog](/platforms/dotnet/guides/serilog/#apps-that-call-usesentry), [NLog](/platforms/dotnet/guides/nlog/#apps-that-call-usesentry) and [log4net](/platforms/dotnet/guides/log4net/#apps-that-call-usesentry) guides show the full setup.
2834

2935
A logging integration sends nothing until you initialize Sentry. SDK settings left on the integration fail in different ways:
3036

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ order: 10
1111

1212
The Serilog sink, the NLog target, the log4net appender and `Logging.AddSentry()` after `SentrySdk.Init` send every entry they receive to Sentry as a log. In 6.x, they sent logs only with `EnableLogs` on, so an upgraded app can send many more logs.
1313

14-
Adding one of these integrations is now the opt-in for its logs. This also applies in ASP.NET Core, MAUI, Blazor WebAssembly and generic host apps. There, `EnableLogs` only controls the `ILogger` integration that `UseSentry` adds. A Serilog, NLog or log4net integration in the same app sends logs whether `EnableLogs` is on or off.
14+
Adding one of these integrations is now the opt-in for its logs, in every kind of app. `EnableLogs` on the options of `UseSentry` doesn't change this. See [EnableLogs Is Removed from SentryOptions](#enablelogs-is-removed-from-sentryoptions).
1515

1616
Each integration sends the entries its logging framework passes to it:
1717

‎includes/migration/dotnet-v7/remove-redundant-loggingaddsentry-calls.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ platformCategory: all
99
order: 50
1010
---
1111

12-
In an app that calls `UseSentry`, `Logging.AddSentry()` now does nothing, and options passed to it in code no longer apply. Move those options to `UseSentry` and remove the call. The exception is an app that calls `ClearProviders()` after `UseSentry`, which also removes Sentry's logger providers: keep `Logging.AddSentry()` there to add them back.
12+
In an app that calls `UseSentry`, `Logging.AddSentry()` now does nothing, and options passed to it in code no longer apply. Move those options to `UseSentry` and remove the call.
1313

14-
In 6.x, an app with both calls captured each error, breadcrumb and log twice. In 7.x, the `ILogger` integration that `UseSentry` adds captures them once, with the options of `UseSentry`. With `Debug` on, the SDK logs a warning that the `Logging.AddSentry()` call can be removed.
14+
The exception is an app that calls `ClearProviders()` after `UseSentry`, which also removes Sentry's logger providers. Keep `Logging.AddSentry()` there to add them back. It uses the options of `UseSentry`, not the ones passed to it. Leave it out if Serilog, NLog or log4net already sends the app's `ILogger` entries to Sentry, because each entry would then arrive twice.
15+
16+
In 6.x, an app with both calls captured each error, breadcrumb and log twice. In 7.x, the `ILogger` integration that `UseSentry` adds captures them once, with the options of `UseSentry`. With `Debug` on, the SDK logs a warning about the redundant call.
1517

1618
In 6.x, the app passed the logging options to `Logging.AddSentry`:
1719

0 commit comments

Comments
 (0)