2

I am using latest Serilog.File 4.1.0 and Serilog.Sinks.Async. Async logging works but I want the files to be rolled. How can I enable rolling of files?

I have the following:

 Log.Logger = new LoggerConfiguration()
                .WriteTo.Async(a =>
                {
                    a.File("logs/logs.log");
                })
                .MinimumLevel.Verbose()
                .CreateLogger();
pantonis
  • 5,601
  • 12
  • 58
  • 115
  • I found it. For anyone out there with the same issue, I installed Serilog.Sinks.RollingFile replaced ```a.File("logs/logs.log");``` with ```a.RollingFile("logs/logs.log");``` – pantonis Apr 08 '20 at 11:17
  • post this as an answer so that people will be benefited. – Saravanan Apr 08 '20 at 14:15
  • 1
    @Ruben Bartelink My purpose was not to add this as an answer that is why I added it as a comment and another member prompted me to post it is as an answer. So I removed my answer and l am leaving the initial post – pantonis Apr 09 '20 at 08:07

1 Answers1

7

The File Sink has support for Rolling files. Just define your rolling policies.

Log.Logger = new LoggerConfiguration()
    .WriteTo.Async(a =>
    {
        a.File("logs/logs.log", rollingInterval: RollingInterval.Hour); // <<<<<
    })
    .MinimumLevel.Verbose()
    .CreateLogger();
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
C. Augusto Proiete
  • 24,684
  • 2
  • 63
  • 91