.NET Core Serilog 日志滚动间隔设置 - 半小时配置
要将日志滚动间隔设置为半小时,您可以在 LoggerConfiguration 中使用 RollingInterval 枚举来设置。以下是一个示例代码:
using Serilog;
using Serilog.Events;
class Program
{
static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File('log.txt', rollingInterval: RollingInterval.HalfHour)
.CreateLogger();
Log.Information('Hello, world!');
Log.CloseAndFlush();
}
}
在上面的示例中,我们将日志写入到文件 'log.txt' 中,并设置了滚动间隔为 RollingInterval.HalfHour,表示每隔半小时就会生成一个新的日志文件。
请注意,上述示例中使用了 Serilog 库来进行日志记录,您可能需要在项目中引用 Serilog 库并进行相应的配置。
原文地址: https://www.cveoy.top/t/topic/qgZ8 著作权归作者所有。请勿转载和采集!