Repository navigation
Description
Problem
Since #4700 (6.0.0, from #4539), logging configuration is meant to control only structured logs. Breadcrumbs and events are controlled by MinimumBreadcrumbLevel, MinimumEventLevel and AddLogEntryFilter alone. Each integration enforces this with a filter rule for its event provider:
builder.AddFilter<SentryLoggerProvider>(_ => true);That works for Logging:Sentry:LogLevel:Default, but not for category entries. A rule such as Logging:Sentry:LogLevel:Noisy also drops breadcrumbs and events from Noisy.*, even when they pass MinimumBreadcrumbLevel and MinimumEventLevel.
Cause
Microsoft.Extensions.Logging picks one filter rule per provider and category. A rule that names the provider beats one that doesn't. Then a longer matching category beats a shorter one or none. Only on a tie does the rule registered last win.
The _ => true rule names the provider but no category, so:
- it ties with
Logging:Sentry:LogLevel:Defaultand wins, because the integration registers it later; - it loses to
Logging:Sentry:LogLevel:<Category>, which names the provider (through theSentryalias) and a category.
The event providers all carry [ProviderAlias("Sentry")] (SentryLoggerProvider, SentryAspNetCoreLoggerProvider, SentryMauiLoggerProvider), and every integration adds the same category-less rule: Sentry.Extensions.Logging, Sentry.Extensions.Hosting, Sentry.AspNetCore, Sentry.Google.Cloud.Functions, Sentry.Maui and Blazor WebAssembly.
Steps to Reproduce
{
"Logging": {
"Sentry": {
"LogLevel": { "Default": "Information", "Noisy": "Error" },
"MinimumBreadcrumbLevel": "Debug",
"MinimumEventLevel": "Warning"
}
}
}var builder = Host.CreateApplicationBuilder(args);
builder.UseSentry(options =>
{
options.Dsn = "...";
options.SetBeforeBreadcrumb(b => { Console.WriteLine($"breadcrumb {b.Category}: {b.Message}"); return b; });
options.SetBeforeSend(e => { Console.WriteLine($"event {e.Logger}"); return e; });
});
using var host = builder.Build();
await host.StartAsync();
var factory = host.Services.GetRequiredService<ILoggerFactory>();
foreach (var category in new[] { "Quiet.Thing", "Noisy.Thing" })
{
var logger = factory.CreateLogger(category);
logger.LogInformation("Information");
logger.LogWarning("Warning");
}Expected Result
Breadcrumbs for both Information entries and an event for both Warning entries. "Noisy": "Error" only stops structured logs from Noisy.Thing.
Actual Result
Logging:Sentry:LogLevel |
Quiet.Thing |
Noisy.Thing |
|---|---|---|
Default: Information, Noisy: Error |
breadcrumbs, event, logs | nothing |
Default: Information |
breadcrumbs, event, logs | breadcrumbs, event, logs |
Default: Error |
breadcrumbs, event, no logs | breadcrumbs, event, no logs |
Reproduced on version7 (9c0f60a), both with UseSentry from Sentry.Extensions.Hosting and with SentrySdk.Init + Logging.AddSentry(). I didn't run ASP.NET Core or MAUI, but they add the same rule. main (6.x) adds it too, so this isn't a regression.
Notes
- A provider can't opt out of a more specific rule that matches it, so this can't be fixed with another
AddFilter. One direction, untested: remove[ProviderAlias("Sentry")]from the event providers, soLogging:Sentryrules only match the structured-log providers. The event providers' options setup would then need to readLogging:Sentrydirectly, becauseILoggerProviderConfiguration<SentryLoggerProvider>finds that section through the alias.SentryHostLoggingOptionsSetupalready reads it directly. - Low priority: it only affects apps with category entries under
Logging:Sentry:LogLevel. - Found while reviewing docs(dotnet): Update Microsoft.Extensions.Logging guide for SDK 7.0.0 sentry-docs#19961 (discussion), which documents the current behaviour. Once this is fixed, remove the sentence there about category entries also filtering breadcrumbs and events.
Activity
linear-code commentedon Nov 3, 2026
NET-905
ric-oliv commentedon Nov 4, 2026
Opened #5869 to see what the fix looks like, and it turned out to be small. What do you think, @jamescrosswell?
I think we could ship it in version7 as well, and call it out in the migration guide: apps with category entries under
Logging:Sentry:LogLevelwill start getting breadcrumbs and events from those categories.fix(logging)!: Stop Logging:Sentry:LogLevel categories filtering brea…
fix(logging): Logging:Sentry:LogLevel category entries no longer filt…
Fix Sentry log levels (#4119)