Skip to content

Document how to initialize Sentry in generic host apps for v7.0.0 #5707

Closed
getsentry/sentry-docs
#20311

Description

@jamescrosswell

#5739 added the Sentry.Extensions.Hosting package on version7, with UseSentry for generic-host apps, and closed #5572. #5740 then stopped Logging.AddSentry() from registering IHub and ISentryClient. This issue is the docs for both.

In 6.x, the only documented way to set up Sentry in a generic-host app (Host.CreateApplicationBuilder(), worker services, Windows services, console apps on the generic host) is builder.Logging.AddSentry(dsn), on the Microsoft.Extensions.Logging page. #5595 removed that path in 7.0.0.

The .NET docs aren't versioned, so the guide merges when 7.0.0 ships.

What to document

This follows the "Docs to write" list in #5739, checked against version7.

  • Install Sentry.Extensions.Hosting and call builder.UseSentry() on IHostApplicationBuilder (.NET 8 and later) or IHostBuilder, with settings from the Sentry section of appsettings.json and the callback. No builder.Logging.AddSentry() alongside it.
  • The SDK starts during Build(), before any hosted service, even when the app clears or replaces the logger providers (fix(hosting): start the SDK during Build() even when the app clears or replaces logger providers #5772). It closes on ApplicationStopped, so a host that's built but never started still reports.
  • The host environment becomes the Sentry environment unless one is set. "Dsn": "" disables the SDK.
  • Logs from ILogger need EnableLogs = true, as on the other host integrations.
  • On .NET Framework, UseSentry is only on IHostBuilder. Apps on Host.CreateApplicationBuilder() there switch to Host.CreateDefaultBuilder(), or use SentrySdk.Init with Logging.AddSentry(). Those that inject IHub, ISentryClient or Func<IHub> then register them with HubAdapter.Instance (feat(mel)!: Logging.AddSentry() no longer registers IHub or ISentryClient #5740).
  • Web and MAUI apps use UseSentry from Sentry.AspNetCore or Sentry.Maui. The generic call steps aside when both are present. With only the generic one, they miss request data and transactions, or UI breadcrumbs, and a warning says so.
  • Aspire's AddServiceDefaults, and any helper declared in the Microsoft.Extensions.Hosting namespace, needs the static SentryWebApplicationBuilderExtensions.UseSentry(web) call, or its MAUI twin.
  • Azure Functions (isolated) apps use the generic UseSentry.
  • ClearProviders() removes Sentry's logger providers if it runs after UseSentry. Call UseSentry after it, or call builder.Logging.AddSentry() after it to add Sentry's providers back (fix(logging): make Logging.AddSentry() work after UseSentry and ClearProviders() #5776). Skip that when NLog, Serilog or log4net already sends the app's ILogger entries to Sentry, or each entry arrives twice (docs: add an ASP.NET Core NLog sample and stop advising AddSentry() when another integration handles ILogger #5821). With Debug = true, the SDK warns when the providers were removed and not added back (fix(logging): warn when ClearProviders() removes the logger providers UseSentry added #5789).
  • Migrating: when adding UseSentry, remove SentrySdk.Init and move its options into the callback or the Sentry section. Whichever init runs last wins, and options don't merge.

Where

Related: #2274 asks for better guidance for .NET Worker Services.

Activity

  1. added
    .NET
    Next Major
    on Oct 12, 2026
  2. linear-code commented on Oct 12, 2026

    @linear-code
  3. added a commit that references this issue on Nov 10, 2026
    3c5edfb
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

    .NETDocsMicrosoft.Extensions.LoggingNext Major

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions