SerilogSinksInMemory icon indicating copy to clipboard operation
SerilogSinksInMemory copied to clipboard

Improve assertions for extension friendliness; add DebuggerTypeProxy for InMemorySink; minor docs fix

Open vfofanov opened this issue 1 month ago • 0 comments

Summary

This PR enhances the Serilog.Sinks.InMemory developer experience and assertions ecosystem:

  • Makes assertion APIs more extension-friendly across multiple target assertion frameworks.
  • Adds a DebuggerTypeProxy for InMemorySink to provide a cleaner debugging view.
  • Performs a focused refactor of InMemorySinkExtensions to improve clarity and extensibility.
  • Minor documentation correction in README.md.

Changes

  • InMemory sink and debugging
    • Added src/Serilog.Sinks.InMemory/InMemorySinkAdvDebugProxy.cs and applied [DebuggerTypeProxy] to InMemorySink.
    • Updated src/Serilog.Sinks.InMemory/InMemorySink.cs to improve snapshot handling and thread-safety around _logEvents and _logEventsSnapshot.
  • Assertion improvements
    • Updated assertion implementations/factories across versions: FluentAssertions5/6/7/8, Shouldly4, and introduced AwesomeAssertions8/9 implementations.
    • Significant refactor in src/Serilog.Sinks.InMemory.Assertions/InMemorySinkExtensions.cs to better support extension scenarios.
  • Abstractions and project
    • Minor adjustments in Serilog.Sinks.InMemory.Assertions.Abstractions including .csproj.
  • Docs
    • README.md typo/wording fix.

Motivation and Context

  • Developers extending or integrating assertions needed clearer extension points and more consistent behaviors across supported assertion libraries.
  • Debugging InMemorySink instances was noisy; the new DebuggerTypeProxy streamlines inspection during tests and development.

Implementation Notes

  • InMemorySink maintains an internal _logEvents list and _logEventsSnapshot with a lock (_snapShotLock) to keep reads fast and consistent while writes invalidate the snapshot.
  • The [DebuggerTypeProxy(typeof(InMemorySinkAdvDebugProxy))] attribute presents key information without exposing internal implementation details.
  • InMemorySinkExtensions refactor reduces duplication and clarifies extension points used by multiple assertion packages.

Breaking Changes

  • None anticipated for public API. Behavior changes are additive and meant to be transparent. If consumers relied on prior debugging visualizations, the DebuggerTypeProxy changes the visual representation in debuggers.

Performance Considerations

  • Snapshotting reduces repeated list allocations on reads, improving performance for test-heavy scenarios.
  • Locking is scoped to snapshot invalidation and append operations only.

vfofanov avatar Oct 22 '25 20:10 vfofanov