SerilogSinksInMemory
SerilogSinksInMemory copied to clipboard
Improve assertions for extension friendliness; add DebuggerTypeProxy for InMemorySink; minor docs fix
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
DebuggerTypeProxyforInMemorySinkto provide a cleaner debugging view. - Performs a focused refactor of
InMemorySinkExtensionsto improve clarity and extensibility. - Minor documentation correction in
README.md.
Changes
- InMemory sink and debugging
- Added
src/Serilog.Sinks.InMemory/InMemorySinkAdvDebugProxy.csand applied[DebuggerTypeProxy]toInMemorySink. - Updated
src/Serilog.Sinks.InMemory/InMemorySink.csto improve snapshot handling and thread-safety around_logEventsand_logEventsSnapshot.
- Added
- Assertion improvements
- Updated assertion implementations/factories across versions:
FluentAssertions5/6/7/8,Shouldly4, and introducedAwesomeAssertions8/9implementations. - Significant refactor in
src/Serilog.Sinks.InMemory.Assertions/InMemorySinkExtensions.csto better support extension scenarios.
- Updated assertion implementations/factories across versions:
- Abstractions and project
- Minor adjustments in
Serilog.Sinks.InMemory.Assertions.Abstractionsincluding.csproj.
- Minor adjustments in
- Docs
README.mdtypo/wording fix.
Motivation and Context
- Developers extending or integrating assertions needed clearer extension points and more consistent behaviors across supported assertion libraries.
- Debugging
InMemorySinkinstances was noisy; the newDebuggerTypeProxystreamlines inspection during tests and development.
Implementation Notes
InMemorySinkmaintains an internal_logEventslist and_logEventsSnapshotwith 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. InMemorySinkExtensionsrefactor 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
DebuggerTypeProxychanges 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.