elastic / ecs-dotnet

https://www.elastic.co/guide/en/ecs-logging/dotnet/current/setup.html
Apache License 2.0
119 stars 59 forks source link

[FEATURE] Elastic.Serilog.Sinks - Allow flushing messages when Serilog sink is disposed #411

Closed kudmax closed 1 month ago

kudmax commented 3 months ago

ECS integration/library project(s): Elastic.Serilog.Sinks

Is your feature request related to a problem? Please describe. If the application shuts down without suitable timeout, all logged messages waiting in the internal buffer will be lost. Unfortunately, there are no flushing capabilities available to process the internal buffer before its OutboundBufferMaxLifetime expires or the maximum number of elements is reached.

Describe the solution you'd like The Serilog static API includes a CloseAndFlush() method that finalizes the underlying configured logger. When invoked, this method disposes the logger, which in turn disposes of all its sinks. If the sink needs to complete logging in a specific way (such as flushing messages temporarily residing in the internal buffer), it should implement IDisposable or IAsyncDisposable.

Considering this, I would propose supplying the Elasticsearch sink with IDisposable implementation that would ensure proper flushing in the hosted channel at dispose, preventing the loss of buffered messages.

lowern1ght commented 1 month ago

+1

Mpdreamz commented 1 month ago

Thanks for highlighting this omission! This will be covered once https://github.com/elastic/ecs-dotnet/pull/440 lands