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?