5

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.

user247702
  • 23,641
  • 15
  • 110
  • 157

1 Answers1

1

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.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101
  • I can't check now cause I'm not at the office, but that's just Serilog flushing isn't it? I call that already. The problem is Akka is removing all custom loggers during shutdown, before all pending log messages have been passed to the custom logger. – user247702 Jan 16 '18 at 22:33
  • 1
    Ah, I see - thanks for the clarification. Sounds like it will need someone with Akka.NET knowledge to weigh in :-) – Nicholas Blumhardt Jan 16 '18 at 23:20
  • Yeah sorry for the confusion, I clarified the question a bit. – user247702 Jan 16 '18 at 23:40