serilog-settings-appsettings icon indicating copy to clipboard operation
serilog-settings-appsettings copied to clipboard

Serilog flushToDiskInterval doesn't work

Open Tabigon opened this issue 5 years ago • 1 comments

Reproduction steps:

  1. Setup Program.cs like this: `public class Program { public static void Main(string[] args) { IConfigurationBuilder configBuilder = new ConfigurationBuilder(); configBuilder.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); IConfiguration config = configBuilder.Build();

         Log.Logger = new LoggerConfiguration()
             .WriteTo.File("Logs/log-{Date}.txt", buffered: true, flushToDiskInterval: TimeSpan.FromSeconds(60))
         .CreateLogger();
    
         CreateWebHostBuilder(args).Build().Run();
     }
    
     public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
     WebHost.CreateDefaultBuilder(args)
         .UseSerilog() // Set serilog as the logging provider.
         .UseStartup<Startup>();
    

    }`

  2. Get logger via DI in some controller: `private ILogger<SampleDataController> _logger;

     public SampleDataController(ILogger<SampleDataController> logger)
     {
         _logger = logger;
     }`
    
  3. Trying to log an event: public IEnumerable<WeatherForecast> WeatherForecasts(int startDateIndex) { _logger.LogInformation("Test message"); return null; }

Expected result: Logs are flushed to disk every minute.

Real result: Logs are flushed right away as log method called

Tabigon avatar Jul 01 '19 11:07 Tabigon

Hi! How are you determining that the flush is immediate? The flushToDiskInterval setting only specifies when an fsync is forced; .NET and Windows/Linux may decide to flush out writes faster than that.

nblumhardt avatar Jul 01 '19 22:07 nblumhardt