我试图将WriteTo.RollingFile与Serilog一起使用,如下所示:
I am trying to use WriteTo.RollingFile with Serilog as the following:
var log = new LoggerConfiguration().WriteTo.RollingFile( @"F:\logs\log-{Date}.txt", LogEventLevel.Debug).CreateLogger(); log.Information("this is a log test");我的理解是,将根据日期创建和命名日志文件,并且还将每天都写入一个新文件,但是同一天我为每个日志条目获取一个新的日志文件! 如何配置Serilog每天写入一个新文件,因此理想情况下我每天只有一个日志文件?
My understanding is that the log file will be created and named based on the date, and also it will write to a new file everyday, however I am getting a new log file for each log entry during the same day! How to configure Serilog to write to a new file every day so ideally I have a single log file per day?
并且是否有任何要删除的归档过程超过7天的文件?
And is there any archiving process to delete files older than 7 days?
推荐答案尝试以下方法:
var log = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.RollingFile(@"f:\log\log.txt", retainedFileCountLimit:7) .CreateLogger();日志文件名将自动为log-20150819.txt等。您无需指定日期。
The log file name will be automatically log-20150819.txt etc. You do not need to specify the date.
更多推荐
Serilog RollingFile
发布评论