Skip to content

Category rules under Logging:Sentry:LogLevel also filter breadcrumbs and events #5860

Description

@jamescrosswell

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:Default and wins, because the integration registers it later;
  • it loses to Logging:Sentry:LogLevel:<Category>, which names the provider (through the Sentry alias) 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, so Logging:Sentry rules only match the structured-log providers. The event providers' options setup would then need to read Logging:Sentry directly, because ILoggerProviderConfiguration<SentryLoggerProvider> finds that section through the alias. SentryHostLoggingOptionsSetup already 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

  1. added
    Bug
    .NET
    on Nov 3, 2026
  2. linear-code commented on Nov 3, 2026

    @linear-code
  3. ric-oliv commented on Nov 4, 2026

    @ric-oliv
    Member

    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:LogLevel will start getting breadcrumbs and events from those categories.

  4. added a commit that references this issue on Nov 4, 2026
    90361e2
  5. added a commit that references this issue on Nov 10, 2026
    ca07b6c
  6. added a commit that references this issue on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETBugMicrosoft.Extensions.Logging

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions