DataDog / serilog-sinks-datadog-logs

Serilog Sink that sends log events to Datadog https://www.datadoghq.com/
Apache License 2.0
60 stars 41 forks source link

No longer works with latest Serilog update of Serilog.Sinks.PeriodicBatching v3.0.0 #82

Closed rog1039 closed 1 year ago

rog1039 commented 1 year ago

Nuget package Serilog.Sinks.PeriodicBatching has dropped inheritance support for PeriodicBatchingSink in the latest version 3.0.0. See here for commit in that repository https://github.com/serilog/serilog-sinks-periodicbatching/pull/56

With PeriodicBatchingSink marked as sealed, DatadogSink now cannot be constructed and will fail at runtime with an exception like this:

System.TypeLoadException: Could not load type 'Serilog.Sinks.Datadog.Logs.DatadogSink' from assembly 'Serilog.Sinks.Datadog.Logs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a460801c7b1366bb' because the parent type is sealed.

Relevant bit from the PR referenced is reproduced here:

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

Thanks!

gh123man commented 1 year ago

Fixed in https://github.com/DataDog/serilog-sinks-datadog-logs/pull/83