Serilog is not writing log to Seq until Log.CloseAndFlush() is invoked

Hasibul picture Hasibul · Sep 16, 2017 · Viewed 9k times · Source

Serilog and Seq works fine when I log from WinForm/web application. I am facing problem only when I am using console application. Without writing Log.CloseAndFlush() it is not working. Following is my LoggerConfiguration

Log.Logger = new LoggerConfiguration()
                .WriteTo.Seq("http://localhost:5341")
                .CreateLogger();

Is there any way to log without invoking Log.CloseAndFlush() so that it works with seq, serilog in console application.

Answer

Nicholas Blumhardt picture Nicholas Blumhardt · Sep 17, 2017

Log.CloseAndFlush() only needs to be called once in a console application, before the application exits. It's a "shutdown" method that ensures any buffered events are processed before the application exits.

The Serilog Lifecycle of Loggers documentation has some more detail on CloseAndFlush().