Serilog RollingFile [英] Serilog RollingFile

查看:375
本文介绍了Serilog RollingFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆