Serilog RollingFile

编程入门 行业动态 更新时间:2024-10-25 02:30:34
本文介绍了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

本文发布于:2023-11-14 11:34:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587105.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Serilog   RollingFile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!