I'm using Serilog and I notice when shutting down the actor system, not all outstanding log messages have been processed before custom loggers like Serilog are removed. Because of this, a bunch of messages are no longer sent to the Serilog sink and they end up in the default logger instead.
As a workaround, I use this in a ReceiveAsync
handler:
await Task.Delay(TimeSpan.FromSeconds(5));
Context.System.Terminate();
I can probably use an AutoResetEvent
or similar in a non-async handler or an FSM OnTermination
handler.
The workaround above is just that though, a workaround. Is there a way to flush the logs? Note that I already flush Serilog before shutting down the actor system, that part works fine.
If you're using the global Log
class, call Log.CloseAndFlush()
before termination.
If you're using an IoC container or similar to manage a Logger
instance separately, that's not assigned to the global Log.Logger
property, make sure the container (or your app code) Dispose()
s the logger instance before termination.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With