Skip to content

Document ClearProviders() in the ASP.NET Core guide for v7.0.0 #5911

Closed
getsentry/sentry-docs
#20715

Description

@jamescrosswell

The Generic Host guide (getsentry/sentry-docs#20311) explains what ClearProviders() does to Sentry's logger providers. The ASP.NET Core guide (docs/platforms/dotnet/guides/aspnetcore/index.mdx) doesn't mention it, but ASP.NET Core's UseSentry registers its providers the same way, so the same advice applies. Raised by @ric-oliv in the review of getsentry/sentry-docs#19961.

Behaviour on version7

Read from version7 (51e7d99), not from running an app:

  • IWebHostBuilder.UseSentry registers SentryAspNetCoreLoggerProvider and SentryAspNetCoreStructuredLoggerProvider through HostLoggerProviders.Add (src/Sentry.AspNetCore/SentryWebHostBuilderExtensions.cs:87), as the Generic Host does (src/Sentry.Extensions.Hosting/SentryHostBuilderExtensions.cs:163). WebApplicationBuilder.UseSentry calls it.
  • builder.Logging.ClearProviders() after UseSentry removes both providers, so ILogger entries no longer become breadcrumbs, events or structured logs.
  • The SDK still starts and the middleware is still added, because SentryStartupFilter calls IApplicationBuilder.UseSentry (src/Sentry.AspNetCore/ApplicationBuilderExtensions.cs:47-50).
  • That method also runs HostLoggerProviders.WarnIfRemoved. The warning goes to the diagnostic logger, so it only shows with Debug = true.
  • builder.Logging.AddSentry() after ClearProviders() adds the ASP.NET Core providers back, using the UseSentry options (src/Sentry.Extensions.Logging/LoggingBuilderExtensions.cs:65-88).

What to add

A short section in the ASP.NET Core guide, matching the Generic Host one:

  • Call ClearProviders() before UseSentry.
  • If the app has to clear providers after UseSentry, call builder.Logging.AddSentry() after ClearProviders(). Skip that if NLog, Serilog or log4net already sends ILogger entries to Sentry, because each entry would then arrive twice.

The AddSentry() re-add and the warning are new in 7.0.0, so this targets dotnet-v7 in getsentry/sentry-docs.

Related: #5755, #5707

Activity

  1. linear-code commented on Nov 11, 2026

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

    @jamescrosswell
    CollaboratorAuthor

    Done in getsentry/sentry-docs#20715, merged into dotnet-v7. It goes live when that branch merges into master with 7.0.0 (getsentry/sentry-docs#20641).

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions