LogFileAppender在log4net的最大文件大小 [英] Maximum Filesize of LogFileAppender in Log4Net
问题描述
我使用log4net的,而现在,这是一个惊人的日志框架,尤其是当勾搭成Castle.Windsor。但是...
I am using Log4net for a while now and it's an amazing logging framework, especially when hooked into Castle.Windsor. However...
我平时使用的滚动文件附加目的地,但是这已经造成了太多的日志文件不是我真正想要的,所以不是,我的最新项目,已使用的基本LogFileAppender代替,但问题是日志文件不断增加(看似永远)。
I usually use the rolling file appender, but this has resulted in too many log files than I actually want, so instead, for my latest project, have used the basic LogFileAppender instead, but the problem is the log file keeps growing (seemingly forever).
我怎么能告诉Appender的不走了一个固定大小(并开始删除旧日志和追加新的文件吗?
How can I tell the appender to not go over a fixed size (and start removing old logs and appending the new ones to the file?
我现在的配置是这样的:
My current configuration looks like:
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="E:\Logs\iWater\Schedule-Dispatch-API.log"/>
<param name="AppendToFile" value="true"/>
<maximumFileSize value="2048KB"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-16date{dd MMM HH:mm:ss} %-7level %-25.35logger{1} %message%newline"/>
</layout>
</appender>
它似乎像maximumFileSize属性不被尊重。任何解决办法?
Its seems like the maximumFileSize attribute is not being respected. Any solutions?
另外,我怎么可以配置滚动文件附加器仅创建1个文件(永远)?
Alternatively, how can I configure the rolling file appender to only create 1 file (ever)?
推荐答案
在FileAppender类不具备MAXFILESIZE / MaximumFileSize性能。如果使用RollingFileAppender进行,你只能得到这些。下面是一个例子,这将限制你的文件到一个固定的最大大小,没有备份(设置maxSizeRollBackups为0)。请注意,当文件达到最大尺寸,它截断(基本上是删除所有现有的记录,并重新开始):
The FileAppender class does not have the MaxFileSize/MaximumFileSize properties. You only get those if you use a RollingFileAppender. Here's an example that will limit your file to a fixed maximum size, with no backups (set maxSizeRollBackups to 0). Note that when the file reaches its max size, it truncates (basically deletes all existing logging and starts over):
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="0" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
这篇关于LogFileAppender在log4net的最大文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!