Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serilog flushToDiskInterval doesn't work #39

Open
Tabigon opened this issue Jul 1, 2019 · 1 comment
Open

Serilog flushToDiskInterval doesn't work #39

Tabigon opened this issue Jul 1, 2019 · 1 comment

Comments

@Tabigon
Copy link

Tabigon commented Jul 1, 2019

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 _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

@nblumhardt
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants