Log4net RollingFileAppender 大小rollingStyle 文件扩展名
我正在使用 RollingFileAppender 和 Size movingStyle。默认情况下,它会创建带有编号扩展名的备份文件,这让我抓狂。是否可以更改它,使其始终使用定义的扩展名(例如 .txt 或 .log)并将数字作为文件名的一部分插入?
例如:
myapp.log
myapp.1.log
myapp.2.log
myapp.3.log
这是我当前的配置:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="myapp.log"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maximumFileSize value="1MB"/>
<maxSizeRollBackups value="10"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{ISO8601} [%3thread] %-5level %logger{3}: %message%newline" />
</layout>
</appender>
I am using the RollingFileAppender
and the Size rollingStyle. By default it creates backup files with a numbered extension, this drives me nuts. Is it possible to change it so it always uses a defined extension (say .txt or .log) and inserts the number as part of the file name?
For example:
myapp.log
myapp.1.log
myapp.2.log
myapp.3.log
Here is my current configuration:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="myapp.log"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maximumFileSize value="1MB"/>
<maxSizeRollBackups value="10"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{ISO8601} [%3thread] %-5level %logger{3}: %message%newline" />
</layout>
</appender>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PreserveLogFileNameExtension
属性设置为 true 应该可以解决问题。 注意:此属性在当前发布的版本 1.2.10 中不可用但是当前源代码的一部分。如果您获取并构建了源代码,那么您就可以开始了。更新:很高兴看到 log4net 不断向前发展。版本 1.2.11 及其
PreserveLogFileNameExtension
属性已发布。The
PreserveLogFileNameExtension
property set to true should do the trick. Note: this property is not available in the currently released version 1.2.10 but is part of the current source. If you grab and build the source you're good to go.Update: it is great to see log4net is moving forward. Version 1.2.11, and with it the
PreserveLogFileNameExtension
property, have been released.