Skip to content

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

Draft
jamescrosswell wants to merge 4 commits intomainfrom
feat/serilog-restricted-to-minimum-level
Draft

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

Conversation

@jamescrosswell
Copy link
Copy Markdown
Collaborator

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)

Test plan

  • All existing Sentry.Serilog.Tests pass
  • New tests added: Sentry_WithRestrictedToMinimumLevel_FiltersLogsBelow and Sentry_WithRestrictedToMinimumLevel_NoDsn_ParameterIsAccepted
  • API approval snapshot files updated

🤖 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 73.57%. Comparing base (32a55e3) to head (2f79b30).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5181      +/-   ##
==========================================
- Coverage   74.06%   73.57%   -0.50%     
==========================================
  Files         501      487      -14     
  Lines       18113    17720     -393     
  Branches     3521     3433      -88     
==========================================
- Hits        13415    13037     -378     
+ Misses       3838     3830       -8     
+ Partials      860      853       -7     

☔ 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 3 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>
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