Skip to content

docs: add an ASP.NET Core NLog sample and stop advising AddSentry() when another integration handles ILogger - #5821

Merged
ric-oliv merged 4 commits into
version7from
nlog-aspnetcore-sample-5763
Oct 28, 2026
Merged

ric-oliv merged 4 commits into
version7from
nlog-aspnetcore-sample-5763

Conversation

@jamescrosswell

@jamescrosswell jamescrosswell commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Adds an ASP.NET Core sample for NLog and changes the guidance that sends ILogger entries to Sentry twice.

  • Sentry.Samples.AspNetCore.NLog: routes ILogger through NLog with UseNLog(new NLogAspNetCoreOptions { ReplaceLoggerFactory = true }). NLog's factory replaces the default one, so the ILogger providers that UseSentry adds never run, and each entry reaches Sentry once, through the NLog target, in either call order. NLog's default UseNLog() adds a provider instead, which duplicates every entry (see the issue).
  • HostLoggerProvidersRemoved warning: it led with "call AddSentry() to add them back". When NLog, Serilog or log4net already forward ILogger entries to Sentry, doing that sends each entry twice. The warning now leads with that case.
  • Logging.AddSentry() remarks (both overloads): say plainly that apps calling UseSentry don't need it, and that it's for adding Sentry's providers back after ClearProviders().

Part of #5763. The sentry-docs changes listed in the issue are separate.

Note: with Debug turned on, this sample (and any UseNLog() + UseSentry app on version7) crashes with a stack overflow. The SDK's diagnostic logs go through ILogger to the NLog Sentry target, which logs diagnostics again. That isn't caused by this PR; it's tracked in #5822.

#skip-changelog

🤖 Generated with Claude Code

…hen another integration handles ILogger

The sample routes ILogger through NLog with ReplaceLoggerFactory, so Sentry's
own ILogger providers stand aside and each entry reaches Sentry once.

The ClearProviders() warning and the AddSentry() remarks told apps to add
Sentry's providers back, which sends every entry twice when NLog, Serilog or
log4net already forward ILogger entries to Sentry.

Refs #5763

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.22%. Comparing base (2194c92) to head (69d16a2).
⚠️ Report is 5 commits behind head on version7.

Additional details and impacted files
@@             Coverage Diff              @@
##           version7    #5821      +/-   ##
============================================
+ Coverage     76.17%   76.22%   +0.04%     
============================================
  Files           526      528       +2     
  Lines         19265    19318      +53     
  Branches       3729     3737       +8     
============================================
+ Hits          14676    14726      +50     
  Misses         3734     3734              
- Partials        855      858       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jamescrosswell and others added 2 commits October 28, 2026 15:01
… Core NLog sample

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/Sentry.Extensions.Logging/SentryLoggingOptions.cs Outdated

@ric-oliv ric-oliv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@ric-oliv
ric-oliv merged commit a56c634 into version7 Oct 28, 2026
38 checks passed
@ric-oliv
ric-oliv deleted the nlog-aspnetcore-sample-5763 branch October 28, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ILogger entries are captured twice when a host integration and the NLog, Serilog or log4net integration are both set up

2 participants