serilog / serilog-sinks-periodicbatching

Infrastructure for Serilog sinks that process events in batches.
Apache License 2.0
70 stars 29 forks source link

Add `IAsyncDisposable` support, drop obsolete inheritance-based APIs #56

Closed nblumhardt closed 1 year ago

nblumhardt commented 1 year ago

Enables asynchronous flushing of queued batches when disposed via IAsyncDisposable.DisposeAsync(). Batched sinks will now also be disposed via DisposeAsync() if they support it.

See also: https://github.com/serilog/serilog/pull/1750

Dropping subclassing support

The interactions of Dispose(), Dispose(bool), DisposeAsync(), and DisposeAsyncCore() make retrofitting support in a base class like PeriodicBatchingSink error-prone, opening the door to skipped disposal or double-disposal in base classes not explicitly written for async disposal.

Since subclassing of PeriodicBatchingSink was already obsoleted, this PR skips the whole unfruitful mess and simply takes the next step by removing subclassing support altogether. Major version bumped to 3.0.0.

Migrating existing code to the new API is easy - instead of deriving from PeriodicBatchingSink, consumers implement IBatchedLogEventSink instead, and wrap an instance of the batched sink in a new PeriodicBatchingSink(batchedSink, options).

nblumhardt commented 1 year ago

Think I've got everything; I'll merge this and queue up a release since we'll want it to go out in sync with Serilog 2.12.0.