按大小滚动时将日期附加到文件名 [英] Appending date to filename when rolling by size

查看:81
本文介绍了按大小滚动时将日期附加到文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想配置log4net,以便在按大小滚动时将名称附加到文件名中.我只玩过log4net的配置部分,不确定是否需要为此在代码中进行配置.
这就是我现在拥有的:

I'd like to configure log4net to append the name to the filenames when rolling by size. I've only played around with the configuration section of log4net, not sure if I have to configure something in code for this.
This is what I have now:

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="C:\\rolling-log.txt" />
  <appendToFile value="true" />
  <datePattern value="_yyyy-MM-dd" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="10KB" />
  <rollingStyle value="Size" />
  <staticLogFileName value="true" />
  <preserveLogFileNameExtension  value="true"/>
  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="%m%n" />
  </layout>
</appender>

如果rollingStyle设置为Date,我只能在文件名中获取日期,但之后大小不再滚动.

I can only get the date in the filename if the rollingStyle is set to Date, but then it doesn't roll on size anymore.

我在这里想念什么?

推荐答案

更改

<file value="C:\\rolling-log.txt" />

<file type="log4net.Util.PatternString" value="C:\\rolling-log-%date{yyy-MM-dd}.txt" />

(或您喜欢的任何日期格式).

(or whatever date pattern you prefer).

注意事项:

不幸的是,仅在配置时评估文件名中指定的日期,这意味着将在每个卷上使用相同的日期,直到重新配置log4net.我没有找到解决此问题的方法.

Unfortunately, the date specified in the filename is only evaluated upon configuration, meaning the same date will be used on each roll until log4net is reconfigured. I have not found a way to fix this.

这篇关于按大小滚动时将日期附加到文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆