我想使用 Serilog 将不同(.NET 框架)应用程序生成的日志写入带有标题的公共文件。要求在达到特定字节限制后拆分文件
https://github.com/serilog/serilog-sinks-fileshared: true
解释了如何通过在WriteTo.File()
记录器配置中使用方法从多个应用程序写入公共文件
https://github.com/cocowalla/serilog-sinks-file-header解释了如何hooks
在WriteTo.File()
方法中添加标题,在记录器配置中这两个单独支持文件被拆分(滚动文件)使用fileSizeLimitBytes
我将记录器配置为:
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();
但我得到了错误Unhandled Exception: System.ArgumentException: File lifecycle hooks are not currently supported for shared log files
有没有办法将这两种功能结合起来,并将标题添加到由多个应用程序共享的 serilog 生成的滚动文件中?