c# - 将标题添加到共享滚动文件 Serilog
问题描述
我想使用 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 生成的滚动文件中?
解决方案
推荐阅读
- javascript - 如何修复 Google 脚本错误“TypeError:无法读取未定义的属性“长度”(第 59 行,文件“代码”)?
- jt400 - IBMi AS400 中的 UPCRTD 属性是什么?
- mysql - 'where' 在此位置无效
- android - 带有导航组件的 Android 深层链接无法按预期工作
- openapi - Swagger-PHP/Doctrine 注释、OpenAPI 3 和 JSON:API 格式
- java - Mockito:如何部分使用 @InjectMocks-Annotation 进行 MockMvc 测试?
- docker - hyperledger fabric 2.0.0 fabcar 运行问题
- android - 在运行 Android 10 的小米设备上,EditText TextInput 中的电子邮件崩溃
- javascript - 将反应类组件转换为功能组件的快速方法?
- java - 如何让一个方法在junit集成测试中什么都不做?