Skip to content

Fix ContextualLogger bypassing Serilog destructuring policies (v11)#873

Merged
mishioo merged 2 commits intov11.0-previewfrom
fix/logs-sanitization-v11
Apr 16, 2026
Merged

Fix ContextualLogger bypassing Serilog destructuring policies (v11)#873
mishioo merged 2 commits intov11.0-previewfrom
fix/logs-sanitization-v11

Conversation

@mishioo
Copy link
Copy Markdown
Contributor

@mishioo mishioo commented Apr 15, 2026

same as #872

Summary

ContextualLogger<T> only implemented Write(LogEvent). On Serilog 4.x, Information, Warning, and similar APIs are default interface methods on Serilog.ILogger that bind templates via an internal unconfigured logger, so registered IDestructuringPolicy instances (including BaseSanitizer<T>) were never applied. Message binding must use the same configured Serilog.ILogger instance that owns the pipeline (including sanitizers).

This change implements BindMessageTemplate on ContextualLogger<T> and forwards to the inner logger. NullLogger<T> implements BindMessageTemplate by returning false so binding does not use the default static implementation.

Test plan

  • Added ContextualLoggerDestructuringTests: configures a logger with Destructure.With<RightSanitizer>(), logs {@Payload} through LeanCode.Logging.ILogger<T> (ContextualLogger), and asserts the captured property reflects sanitization (placeholder present, raw secret string absent).

Notes

  • NullLogger: returning false from BindMessageTemplate avoids constructing log events from the default binding path; behavior remains a no-op for logging.

Made with Cursor.

@github-actions
Copy link
Copy Markdown

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
947 946 0 1 0 0 1m 54s

Skipped

Tests Status
LeanCode.Azure.Tests.AzureStorageAuditLogIntegrationTests.Ensure_that_all_logs_are_correctly_uploaded_to_multiple_files skipped ⏭️

🎉 No failed tests in this run.

Github Test Reporter by CTRF 💚

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.41%. Comparing base (dc31091) to head (d050205).
⚠️ Report is 3 commits behind head on v11.0-preview.

Additional details and impacted files
@@                Coverage Diff                @@
##           v11.0-preview     #873      +/-   ##
=================================================
- Coverage          85.57%   85.41%   -0.17%     
=================================================
  Files                246      246              
  Lines               5206     5210       +4     
  Branches             388      379       -9     
=================================================
- Hits                4455     4450       -5     
- Misses               668      676       +8     
- Partials              83       84       +1     

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

@mishioo mishioo merged commit a04341e into v11.0-preview Apr 16, 2026
7 of 8 checks passed
@mishioo mishioo deleted the fix/logs-sanitization-v11 branch April 16, 2026 08:51
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.

2 participants