feat: log4net appender no longer initializes the SDK - #5592
Draft
jamescrosswell wants to merge 9 commits into
Draft
jamescrosswell wants to merge 9 commits into
jamescrosswell wants to merge 9 commits into
Conversation
The Sentry appender for log4net now only sends log events to Sentry. Sentry must be initialized separately (SentrySdk.Init, UseSentry, etc). - Remove SentryAppender.Dsn and the lazy SDK initialization on first append - Remove SentryAppender.Environment; events take the environment from the options used to initialize Sentry - Remove the OnClose override, which only disposed the SDK the appender had initialized Part of #5245 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/no-init-from-logging-nlog-5245 #5592 +/- ##
=======================================================================
- Coverage 74.64% 74.60% -0.04%
=======================================================================
Files 514 514
Lines 18760 18732 -28
Branches 3647 3640 -7
=======================================================================
- Hits 14003 13975 -28
Misses 3889 3889
Partials 868 868 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jamescrosswell
commented
Sep 17, 2026
jamescrosswell
commented
Sep 17, 2026
jamescrosswell
commented
Sep 17, 2026
| // Honor the appender-level settings, overriding the scope/options defaults, to match the SentryEvent path. | ||
| if (!string.IsNullOrWhiteSpace(environment)) | ||
| { | ||
| log.SetAttribute("sentry.environment", environment!); |
Collaborator
Author
There was a problem hiding this comment.
This gets handled here now (just a couple of lines up):
…from-logging-log4net-5245
Sdk.Name should identify the integration that initialised the hub, which after this change can no longer be a logging integration. The appender identifies itself through the log origin (auto.log.log4net) instead. See #5497. Events are no longer stamped with sentry.dotnet.log4net, and structured logs no longer carry it as sentry.sdk.name; both now report the SDK that initialised Sentry. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…245' into feat/no-init-from-logging-log4net-5245
…ion error Brings back SentryAppender.Dsn as a tombstone: [Obsolete(error: true)] with a setter that throws NotSupportedException carrying migration guidance, so code callers get a compile error and XML configs report the message instead of log4net's "Cannot find Property [Dsn]". Unlike Serilog and NLog, this cannot fail configuration loading: log4net catches exceptions thrown while setting a parameter, so the appender is still attached and the message surfaces through log4net's internal logging. Part of #5245 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…245' into feat/no-init-from-logging-log4net-5245
Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
…245' into feat/no-init-from-logging-log4net-5245
…t-5245' into feat/no-init-from-logging-log4net-5245
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The log4net portion of #5245, stacked on #5585 (NLog) and following the same design. The Sentry appender for log4net now only sends log events to Sentry; Sentry has to be initialized separately via
SentrySdk.Init,UseSentry, etc.Part of #5245
Breaking changes
SentryAppender.Dsnremains as a tombstone —[Obsolete(..., error: true)]with a setter that throwsNotSupportedExceptioncarrying migration guidance, matching feat(serilog): configuring a DSN on the sink now fails with a migration error #5611 (Serilog) and feat: NLog target no longer initializes the SDK #5585 (NLog).SentryAppender.Environmentis removed. Events and structured logs take the environment from the options used to initialize Sentry.SentryAppenderno longer overridesOnClose. It only existed to dispose the SDK the appender had initialized, so closing the log4net repository no longer flushes Sentry; disposing the handle fromSentrySdk.Initdoes.Before:
After:
The tombstone behaves differently here than in Serilog and NLog
log4net cannot be made to fail configuration loading.
XmlHierarchyConfigurator.SetParametercatches exceptions thrown while setting a parameter, so the throwing setter does not propagate: the config still loads and the appender is still attached. Verified, rather than assumed:app.configwith<Dsn value="…" />log4net:ERROR … Cannot find Property [Dsn] to set object on [Sentry.Log4Net.SentryAppender], config loads, appender attachedlog4net:ERROR Failed to set parameter [Dsn] … NotSupportedException: <migration message>, config loads, appender attachedappender.Dsn = "…"in codeCS1061: SentryAppender does not contain a definition for 'Dsn'CS0619carrying the migration messageapp.configwithout<Dsn>So the gain is a better message on the XML path and a compile error carrying migration guidance on the code path — not the hard startup failure Serilog and NLog get. Both messages go to
Console.Errorvia log4net's internal logging unless quiet mode is on.If a hard failure matters more than keeping the appender working, the alternative is to record the attempt in the setter and throw from
ActivateOptions.ParseAppendercatches that too, but it drops the appender entirely, so nothing reaches Sentry at all — worse for anyone who initializes correctly but leaves a stale<Dsn>behind. I went with the setter; say the word if you'd rather have the louder one.Notes for review
Dsnwas set.IsEnabled == false, and events were only captured because the mocked init had run.Environmentgets no tombstone, following feat: NLog target no longer initializes the SDK #5585, which tombstoned only the SDK-init settings. It's a one-line addition if you'd rather it carried a message too — log4net reports the removal either way, just less usefully.UseLog4Net(): identity and properties are applied by the appender to the events and logs it creates.ApiApprovalTests.Run.Net4_8andDotNet10_0are copies of the regeneratedDotNet11_0snapshot, which all three matched byte-for-byte beforehand.Net4_8can't regenerate on macOS, andDotNet10_0isn't run at all since the test project only targets the latest TFM.🤖 Generated with Claude Code