feat(serilog): support restrictedToMinimumLevel when configuring Serilog in code#5181
feat(serilog): support restrictedToMinimumLevel when configuring Serilog in code#5181jamescrosswell wants to merge 5 commits intomainfrom
Conversation
…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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
…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 | |||
| { | |||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@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?
Summary
Fixes #4957
restrictedToMinimumLevelandlevelSwitchparameters to all threeSentry()extension method overloads onLoggerSinkConfigurationSink()call, enabling per-sink minimum level filtering to be set in codeappsettings.json; this change unblocks MAUI users who configure Serilog in codeUsage
🤖 Generated with Claude Code