Log4Net Rolling File Appender 滚动问题
我有以下 log4net 配置:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="Logs/%date{yyyy-MM-dd} Service.log" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Date"/>
<datePattern value="yyyy-MM-dd"/>
<maxSizeRollBackups value="100"/>
<maximumFileSize value="15MB"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger: %message%newline" />
</layout>
</appender>
数据将不断记录到日志文件中并滚动正常,但我最终得到如下滚动文件:
2009-12-21 Service.log2009-12-22 (this is what it will write tonight)
2009-12-21 Service.log <-- this being the latest file
2009-12-21 Service.log2009-12-21 <-- last updated 23:59
我希望文件如下所示:
2009-12-21 Service.log
2009-12-22 Service.log
2009-12-23 Service.log
I have the following log4net config:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="Logs/%date{yyyy-MM-dd} Service.log" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Date"/>
<datePattern value="yyyy-MM-dd"/>
<maxSizeRollBackups value="100"/>
<maximumFileSize value="15MB"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger: %message%newline" />
</layout>
</appender>
Data will be logged constantly to the log file and rolls OK but I end up having rolled files like this:
2009-12-21 Service.log2009-12-22 (this is what it will write tonight)
2009-12-21 Service.log <-- this being the latest file
2009-12-21 Service.log2009-12-21 <-- last updated 23:59
I want the files to be like:
2009-12-21 Service.log
2009-12-22 Service.log
2009-12-23 Service.log
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除文件元素中的文件名和类型:
然后将 datePattern 更改为(注意:确保转义“Service”中的字母' 适当地,就像 'log' 中的 g 是一种特殊格式,所以你需要用 '\' 对其进行转义):
Get rid of the file name and the type in the file element:
<file value="Logs\" />
Then change your datePattern to (note: make sure you escape the letters in 'Service' appropriately, like the g in 'log' is a special format, so you need to escape it with the '\'):
我认为以下内容应该是您所需要的。
在中添加以下元素。
I think the following should be what you need.
Add in the following element within your <appender />.
您可以使用下面的功能。
在此函数中,首先获取您在 webconfig 中设置的文件位置,然后您可以添加任何您想要的路径! (例如日期、我们的客户或...)
WebConfig:
功能:
结果如下:
C:\Logs\TestProject\Customer1\Saturday, August 31, 2013.log
You can use the function below.
In this function first get file location that you set in webconfig and after that you can add any path that you want! (like Date, our Customer, or...)
WebConfig:
Function:
and result like this:
C:\Logs\TestProject\Customer1\Saturday, August 31, 2013.log