问题标签 [serilog.extensions.logging.file]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
359 浏览

logging - Serilog 日志记录到工作服务.net core 3.1 中的文件

我是工人服务的新手。我在 .net core 3.1 中创建了工人服务。参考本教程使用 serilog 在 .Net 5 worker 服务中记录文件。 它按预期工作,即它正在记录到文件中。现在我安装了我必须使用的服务

Microsoft.Extensions.Hosting.WindowsServices

并修改代码如下。

现在,当我运行该服务时,它没有记录到文件中。我错过了什么吗?

0 投票
0 回答
71 浏览

c# - 将标题添加到共享滚动文件 Serilog

我想使用 Serilog 将不同(.NET 框架)应用程序生成的日志写入带有标题的公共文件。要求在达到特定字节限制后拆分文件

https://github.com/serilog/serilog-sinks-fileshared: true解释了如何通过在WriteTo.File()记录器配置中使用方法从多个应用程序写入公共文件

https://github.com/cocowalla/serilog-sinks-file-header解释了如何hooksWriteTo.File()方法中添加标题,在记录器配置中这两个单独支持文件被拆分(滚动文件)使用fileSizeLimitBytes

我将记录器配置为:

但我得到了错误Unhandled Exception: System.ArgumentException: File lifecycle hooks are not currently supported for shared log files

有没有办法将这两种功能结合起来,并将标题添加到由多个应用程序共享的 serilog 生成的滚动文件中?