Skip to content

feat(serilog): support restrictedToMinimumLevel when configuring Serilog in code#5181

Open
jamescrosswell wants to merge 5 commits intomainfrom
feat/serilog-restricted-to-minimum-level
Open

feat(serilog): support restrictedToMinimumLevel when configuring Serilog in code#5181
jamescrosswell wants to merge 5 commits intomainfrom
feat/serilog-restricted-to-minimum-level

Conversation

@jamescrosswell
Copy link
Copy Markdown
Collaborator

@jamescrosswell jamescrosswell commented May 4, 2026

Summary

Fixes #4957

  • Added restrictedToMinimumLevel and levelSwitch parameters to all three Sentry() extension method overloads on LoggerSinkConfiguration
  • These parameters are passed through to Serilog's underlying Sink() call, enabling per-sink minimum level filtering to be set in code
  • Previously, per-sink minimum levels could only be configured via appsettings.json; this change unblocks MAUI users who configure Serilog in code

Usage

.WriteTo.Sentry(o =>
{
    o.MinimumBreadcrumbLevel = LogEventLevel.Debug;
    o.MinimumEventLevel = LogEventLevel.Error;
}, restrictedToMinimumLevel: LogEventLevel.Warning)

🤖 Generated with Claude Code

…log in code

Add `restrictedToMinimumLevel` and `levelSwitch` parameters to all three
`Sentry()` extension method overloads on `LoggerSinkConfiguration`, passing
them through to Serilog's underlying `Sink()` call. This allows per-sink
minimum level filtering to be configured in code (e.g. for MAUI users) rather
than only via appsettings.json.

Fixes #4957

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jamescrosswell jamescrosswell requested a review from Flash0ver as a code owner May 4, 2026 04:11
Comment thread test/Sentry.Serilog.Tests/SentrySerilogSinkExtensionsTests.cs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.13%. Comparing base (32a55e3) to head (3516b83).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5181      +/-   ##
==========================================
+ Coverage   74.06%   74.13%   +0.07%     
==========================================
  Files         501      506       +5     
  Lines       18113    18255     +142     
  Branches     3521     3564      +43     
==========================================
+ Hits        13415    13533     +118     
- Misses       3838     3852      +14     
- Partials      860      870      +10     

☔ View full report in Codecov by Sentry.
📢 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 draft May 4, 2026 05:25
jamescrosswell and others added 4 commits May 5, 2026 13:50
…rySerilogOptions

Move restrictedToMinimumLevel and levelSwitch out of separate overload
parameters and into SentrySerilogOptions as first-class properties, consistent
with how all other Serilog options are handled. ConfigureSentrySerilogOptions
now sets them alongside the rest of the configuration, and the
Action<SentrySerilogOptions> overload reads them from options when calling
loggerConfiguration.Sink().

This is the idiomatic pattern for the codebase and means MAUI users can
configure everything uniformly via the options callback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ilter test

Use a mock hub with an internal SentrySink and wire it to Serilog via
loggerConfiguration.Sink(sink, options.RestrictedToMinimumLevel, ...) — the
same call the extension method makes — so we can assert that Warning events
are filtered by Serilog before reaching the hub, while Error events get through.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@@ -21,7 +23,7 @@ namespace Serilog
public static class SentrySinkExtensions
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding optional parameters to public Sentry() overloads is a binary-breaking change

Adding new optional parameters (restrictedToMinimumLevel, levelSwitch) to the existing public Sentry() extension methods changes their metadata signatures. While source-compatible, this is binary-breaking in .NET: consumers compiled against a previous version of Sentry.Serilog will get a MissingMethodException at runtime until they recompile. For a public library this is an API contract change that warrants senior engineer review and, ideally, preservation of the prior signatures via additional overloads instead of in-place parameter additions.

Verification

Read src/Sentry.Serilog/SentrySinkExtensions.cs and confirmed the two affected overloads (lines 86-113 and 180-187) had new optional parameters appended rather than being introduced as new overloads. Verified that the API approval snapshot reflects the same signature change at lines 24 and 49-53 of the .verified.txt hunk. .NET's binding to optional parameters is resolved at the call site at compile time, so adding optional parameters changes the method's metadata token and breaks binary compatibility, even though source compiles unchanged.

Identified by Warden code-review · PB4-XBA

Copy link
Copy Markdown
Collaborator Author

@jamescrosswell jamescrosswell May 7, 2026

Choose a reason for hiding this comment

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

@Flash0ver I'd rather go with a binary breaking change here (it's source compatible). The signatures get really messy if we try to add overloads (there are domino effects).

I don't think there are many people swapping out the Sentry dll without recompiling their apps when they upgrade (I'd venture to say probably none)... and accessing functionality like this via reflection also seems highly improbable.

How do you feel about that?

@jamescrosswell jamescrosswell marked this pull request as ready for review May 7, 2026 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support restrictedToMinimumLevel when configuring Serilog in code

1 participant