|
| 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). |
0 commit comments