Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 497
Hasibul Avatar asked Sep 16 '17 16:09

Hasibul


1 Answers

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

like image 144
Nicholas Blumhardt Avatar answered Nov 03 '22 03:11

Nicholas Blumhardt