Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
38 changes: 35 additions & 3 deletions includes/migration/dotnet-v7/logging-integrations-send-logs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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);
Expand All @@ -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<LoggerFilterOptions>(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.
2 changes: 1 addition & 1 deletion platform-includes/logs/options/dotnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>` are sent to Sentry according to your configured provider/category filters and log levels.

Expand Down
Loading