简体   繁体   English

log4net滚动文件appender(按日期)覆盖现有文件

[英]log4net rolling file appender (by date) overwriting existing file

I've currently got a log4net rolling file appender, based on date that should be rolling over each day. 我目前有一个log4net滚动文件appender,基于应该每天滚动的日期。 It has been doing that for months without a problem - but in the last week it has begun overwriting the existing log at some point during the day. 它已经持续了好几个月没有问题 - 但在上周它已经开始在白天的某个时候覆盖现有的日志。 It seems to be doing that when the log file has hit around 10mb. 当日志文件达到10mb左右时似乎正在这样做。

This is the config: 这是配置:

<appender name="Standard" type="log4net.Appender.RollingFileAppender">
  <file value="..\..\Logs\" />
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <staticLogFileName value="false" />
  <datePattern value="yyyy-MM-dd'.log'" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%d{yyyy-MM-dd HH:mm} %-5level %message%newline%exception" />
  </layout>
  <filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="DEBUG" />
    <levelMax value="WARN" />
  </filter>
</appender>

My theory is that the rolling style isn't specified, and a maximum size isn't specified, and the default setting for each is Composite and 10mb. 我的理论是没有指定滚动样式,并且没有指定最大尺寸,并且每个的默认设置是Composite和10mb。 Therefore when it reaches 10mb it starts to roll over, and since the static log file name is set to false, it just rewrites over the current file. 因此,当它达到10mb时,它开始翻转,并且由于静态日志文件名设置为false,它只会重写当前文件。

Is that the case? 是这样的吗? Or is there some other issue at work here? 或者在这里有其他问题吗? I've added 我已经添加

<rollingStyle value="Date"/> 

now, and will see how it goes. 现在,并将看到它如何。 But getting an explanation of why this happened would be great. 但要解释为什么会发生这种情况会很棒。

Thanks! 谢谢!

It looks like my theory was correct! 看起来我的理论是正确的! The default file size is 10mb, and the default rolling style is composite. 默认文件大小为10mb,默认滚动样式为复合。 Combined with the non static file name, when it reached 10mb, it just rolled over to the same file and began logging again. 结合非静态文件名,当它达到10mb时,它只是转到同一个文件并再次开始记录。

您可以随时更改日期模式

 <param name="DatePattern" value="yyyy-MM-dd-hh'.log'" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM