Not all log entries are written when using serilog and Winforms app

277 Views Asked by At

I´ve searched Google & Co quite a while without any result, so sorry if my question has been answered somewhere else...

I´ve been using Serilog within Blazor server apps with no problems and decided to use Serilog for my Winforms apps as well. Conditions under which I'm using Serilog: Winforms, Framework 4.7.2, Windows 10. Unfortunately it seems that, when I'm taking a look into the written log-files, the last 1-5min of logging are missing and are never written - no matter how often I call Log.CloseAndFlush. This behavior is not exactly reproducable - sometimes all entries have been written, sometimes not.

This is how I initialize Serilog:

Serilog.Log.Logger = new LoggerConfiguration()
                .Enrich.FromLogContext()
                .MinimumLevel.ControlledBy(levelSwitch)
                .WriteTo.File(new Classes.SewCompactJSonFormatter(), 
                    m_file,
                    rollingInterval: RollingInterval.Day,
                    fileSizeLimitBytes: _50MB,
                    retainedFileCountLimit: 5,
                    rollOnFileSizeLimit: true,
                    shared: true,
                    flushToDiskInterval: TimeSpan.FromMilliseconds(1000))
                .CreateLogger();

I call the CloseAndFlush on certain user actions. But even directly after that it is not guaranteed that all logs are written.

0

There are 0 best solutions below