2

I want to use Serilog to write logs generated by different (.NET framework) applications to a common file with headers. It is required that the file be split after a particular byte limit is reached

https://github.com/serilog/serilog-sinks-file explains how it is possible to write to a common file from multiple applications by using shared: true in the WriteTo.File() method, in the logger configuration

https://github.com/cocowalla/serilog-sinks-file-header explains how to add headers using hooks in the WriteTo.File() method, in the logger configuration Both of these individually support files to be split (rolling files) using fileSizeLimitBytes

I configured the logger as:

Log.Logger = new LoggerConfiguration()
                    .Enrich.FromLogContext()
                    .WriteTo.File(path, rollOnFileSizeLimit: true, fileSizeLimitBytes:5000, 
                                  retainedFileCountLimit: null, shared: true, 
                                  outputTemplate:"{Level} {Timestamp:yyyy-MM-dd HH:mm:ss.fff} {Message} {MachineName}{NewLine}",
                                  hooks: new HeaderWriter("Level Timestamp Message MachineName"))
                    .CreateLogger(); 

But I got the error Unhandled Exception: System.ArgumentException: File lifecycle hooks are not currently supported for shared log files

Is there a way to combine both the features and add headers to rolling files generated by serilog that is shared by multiple applications?

  • You have not asked a question. I assume it would be "how do I share the log file and write headers" . Protip - You will get much better answers if you attempt and put snippets of your code and describe what issue you had. StackExchange can be kind of harsh if people do not attempt first and share what they tried. – Eric Snyder Oct 27 '21 at 16:27
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 27 '21 at 16:27

0 Answers0