达到maximumFileSize时,log4net滚动文件追加程序文件名格式 [英] log4net rolling file appender file name format when maximumFileSize reached
问题描述
我们正在使用log4net滚动文件附加器,并且对我们的日志文件有以下要求:
We're using the log4net rolling file appender and have the following requirements for our log files:
- 每天开始时都有一个新的日志文件,文件名中带有日期
- 最大日志文件大小为500KB
我们遇到的问题是文件达到500KB时的文件命名策略:它们使用后缀.1
重命名.这是有问题的,因为它破坏了Windows中的文件关联,因此(稍微)增加了琐碎的工作.
The issue we are having is the file naming strategy when files hit 500KB: they get renamed with a .1
suffix. This is problematic as it breaks file association in Windows, so opening the files is (slightly) more of a chore.
我们正在使用的配置是:
The configuration we're using is:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="c:\log\path" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value=".yyyy-MM-dd.lo\g" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<maxSizeRollBackups value="50" />
<maximumFileSize value="500KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %message%newline" />
</layout>
</appender>
是否支持指定当文件命中maximumFileSize
时使用的命名策略?
Is there support for specifying the naming strategy used when our files hit the maximumFileSize
?
推荐答案
Version 1.2.11 of log4net includes the PreserveLogFileNameExtension property on the RollingFileAppender
. Setting the property to true will allow files to be rolled in the format logName.roll#.fileExt, keeping your file associations intact.
appender块中的条目如下所示:
<param name="PreserveLogFileNameExtension" value="true" />
The entry inside the appender block would look like:
<param name="PreserveLogFileNameExtension" value="true" />
这篇关于达到maximumFileSize时,log4net滚动文件追加程序文件名格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!