Skip to content

feat(mel)!: remove ILoggerFactory.AddSentry() in favour of ILoggingBuilder.AddSentry() - #5921

Merged
ric-oliv merged 1 commit into
version7from
ai/remove-iloggerfactory-addsentry
Nov 12, 2026
Merged

ric-oliv merged 1 commit into
version7from
ai/remove-iloggerfactory-addsentry

Conversation

@jamescrosswell

Copy link
Copy Markdown
Collaborator

ILoggerFactory.AddSentry() only added the events provider (SentryLoggerProvider). Unlike ILoggingBuilder.AddSentry(), it never sent structured logs, didn't bind the Logging:Sentry configuration section, and didn't add the Sentry.ISentryClient filter that keeps the structured logger from logging its own diagnostics recursively. ILoggerFactory has no AddFilter, so making the two overloads behave the same would mean a second code path to maintain.

This turns the overload into an [Obsolete(error: true)] stub that throws NotSupportedException, like ILoggingBuilder.AddSentry(string dsn) on this branch. The compile error tells users to add Sentry while building the factory:

using var loggerFactory = LoggerFactory.Create(builder => builder.AddSentry());

Most existing callers have to change this line in 7.0 anyway, because SentryLoggingOptions.Dsn and InitializeSdk are already error-level obsolete, which breaks the new LoggerFactory().AddSentry(o => o.Dsn = ...) form from the 6.x docs.

LoggerFactory.Create was added in Microsoft.Extensions.Logging 3.0. Apps on the netstandard2.0 floor (MEL 2.1) can use new ServiceCollection().AddLogging(b => b.AddSentry()).BuildServiceProvider().GetRequiredService<ILoggerFactory>() instead.

Closes #5908

🤖 Generated with Claude Code

The ILoggerFactory overload only added the events provider, so apps using
it got no structured logs, no IConfiguration binding and no recursion
filter. It's now an error-level obsolete stub that points to
LoggerFactory.Create(builder => builder.AddSentry()).

Closes #5908

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

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.98%. Comparing base (25b505e) to head (61d3cc2).
⚠️ Report is 23 commits behind head on version7.

Files with missing lines Patch % Lines
...xtensions.Logging/SentryLoggerFactoryExtensions.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           version7    #5921   +/-   ##
=========================================
  Coverage     76.98%   76.98%           
=========================================
  Files           538      538           
  Lines         19714    19716    +2     
  Branches       3872     3873    +1     
=========================================
+ Hits          15176    15179    +3     
- Misses         3666     3667    +1     
+ Partials        872      870    -2     

☔ 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
jamescrosswell marked this pull request as ready for review November 12, 2026 05:14
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 12, 2026
@jamescrosswell jamescrosswell linked an issue Nov 12, 2026 that may be closed by this pull request
@jamescrosswell jamescrosswell mentioned this pull request Nov 12, 2026
16 of 19 tasks

@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.

LGTM! .NET Framework apps get Microsoft.Extensions.Logging 2.1 from our package, and that has no LoggerFactory.Create, so I added a line about it to the MEL guide in getsentry/sentry-docs#20752.

@ric-oliv
ric-oliv merged commit a73e2f8 into version7 Nov 12, 2026
51 checks passed
@ric-oliv
ric-oliv deleted the ai/remove-iloggerfactory-addsentry branch November 12, 2026 10:51
jamescrosswell pushed a commit to getsentry/sentry-docs that referenced this pull request Nov 12, 2026
…s.Logging for SDK 7.0.0 (#20752)

<!-- Keep the urgency section so automation can prioritize this PR. You
may delete other sections you don't need. -->

## DESCRIBE YOUR PR

On .NET Framework, `Sentry.Extensions.Logging` brings in
`Microsoft.Extensions.Logging` 2.1. That version has no
`LoggerFactory.Create`, and the app doesn't get `ServiceCollection`
either, so neither setup example on the MEL page compiles there.
Installing the `Microsoft.Extensions.Logging` package fixes both. This
adds a line saying so under Install.

getsentry/sentry-dotnet#5921 sends callers of
`ILoggerFactory.AddSentry()` to `LoggerFactory.Create`, so those apps
end up on this page.

It targets `dotnet-v7`, so it goes live with the rest of the 7.0.0 docs
in #20641.

Refs getsentry/sentry-dotnet#5921

## IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
Select exactly one option. For deadlines, replace `YYYY-MM-DD` with the
due date. You can update this information later by editing the PR
description.

- [x] Urgent deadline (GA date, etc.): the .NET SDK 7.0.0 release, with
#20641
- [ ] Other deadline: YYYY-MM-DD
- [ ] No deadline: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
supplied a deadline.

Thanks in advance for your help!

## PRE-MERGE CHECKLIST

_Make sure you've checked the following before merging your changes:_

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

## EXTRA RESOURCES

- [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

ILoggerFactory.AddSentry() sends no structured logs

2 participants