Home > Software engineering >  Serilog - How to roll over after every 8 hours?
Serilog - How to roll over after every 8 hours?

Time:08-31

I have the following code, which rolls over logs everyday:

Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
            .Enrich.FromLogContext()
            .WriteTo.File(path: "C:\\WRS\\log-.txt",
                outputTemplate: "Time:{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
                rollingInterval: RollingInterval.Day,
                restrictedToMinimumLevel: LogEventLevel.Information
             )
            .CreateLogger();

However, I would like to set the roll over to every 8 hours instead of every day. Is this possible?

CodePudding user response:

However, I would like to set the roll over to every 8 hours instead of every day. Is this possible?

At present, it seems that it is impossible.

If you check the RollingInterval enum value, you can see that it contains Minute, Hour, Day, Month, Year, and Infinite.

enter image description here

From these threads: Precise rolling interval and Added Week to the RollingInterval enum. We can see that the Serilog Develop team has not planned to add this kind option to set the granular rolling intervals.

So you can have to use RollingInterval.Day or RollingInterval.Hour.

  • Related