将 Serilog 文件接收器配置为每个应用程序使用一个日志文件 运行

Configure Serilog File sink to use one log file per application run

我想配置 Serilog 为每个应用程序创建一个日志文件 运行。
文件名应基于当前 date/time:
第一 运行: log_20180413_1020.txt
第二 运行: log_20180413_1033.txt

我没有在任何文件接收器(滚动、替代..)中找到如何做到这一点
有什么线索吗?

配置没有任何滚动周期或大小限制的 Serilog.Sinks.File 接收器,并在启动时配置日志记录时将时间戳添加到日志文件名中:

string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmm");
var log = new LoggerConfiguration()
    .WriteTo.File($"log{timestamp}.txt")
    .CreateLogger();

根据自述文件的 Rolling Policies 部分:

Specifying both rollingInterval and rollOnFileSizeLimit will cause both policies to be applied, while specifying neither will result in all events being written to a single file.