Skip to content

NLog: AddSentry() has no minimum level, so Trace and Debug entries routed through NLog are sent as logs #5909

Closed

Description

@jamescrosswell

LoggingConfiguration.AddSentry() adds a rule for every level (configuration.AddRuleForAllLevels(targetName) in src/Sentry.NLog/ConfigurationExtensions.cs). In 7.0, the Sentry target sends every entry it receives as a structured log. SentryNLogOptions has MinimumEventLevel and MinimumBreadcrumbLevel, but nothing that limits logs.

This matters when an app routes its ILogger entries through NLog with AddNLog(new NLogProviderOptions { ReplaceLoggerFactory = true }), as the 7.0 docs recommend for apps that call UseSentry. NLog's rules then replace the levels in the Logging section, so with AddSentry() every Trace and Debug entry from ASP.NET Core goes to Sentry as a log. @ric-oliv measured 15 Debug and 2 Trace logs for starting a minimal app, serving one request and stopping it (getsentry/sentry-docs#19925).

The docs now work around it by adding the rule themselves:

config.AddRule(NLog.LogLevel.Info, NLog.LogLevel.Fatal, new SentryTarget());

That skips AddSentry(), and needs the NLog.LogLevel prefix in ASP.NET Core apps, where LogLevel is ambiguous.

Proposal

Logs need a minimum level that is separate from breadcrumbs and events. An app that wants Trace breadcrumbs but only Info and higher as logs should be able to have both.

MEL is the ideal. Logs come from their own provider, SentryStructuredLoggerProvider, aliased Sentry, so Logging:Sentry:LogLevel filters logs without touching breadcrumbs or events.

NLog can't do that. A single SentryTarget sends events, breadcrumbs and logs, and NLog's rules decide what reaches the target as a whole. A rule (or a minLevel parameter on AddSentry() that adds one) would filter breadcrumbs and events along with logs.

So follow Serilog, with NLog's rules as the gate. In Serilog, RestrictedToMinimumLevel gates everything that reaches the sink, and MinimumEventLevel and MinimumBreadcrumbLevel set thresholds for each kind of data. In NLog:

  • The rule plays the part of RestrictedToMinimumLevel, as it already does.
  • SentryNLogOptions gets MinimumLogLevel, next to MinimumEventLevel and MinimumBreadcrumbLevel. It defaults to Info, only filters logs, and is also a target attribute (minimumLogLevel) for XML config.

With the Info default, the docs can go back to a plain config.AddSentry(...). Changing the default is easiest before 7.0.0.

Activity

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

    @linear-code
  3. added a commit that references this issue on Nov 11, 2026
    84d6864
  4. jamescrosswell commented on Nov 11, 2026

    @jamescrosswell
    CollaboratorAuthor

    Fixed in #5913 on version7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETImprovementLogsNLogState: Needs Discussion

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions