开发者

Log4Net composite RollingFileAppender with static file extension

Does the current version of Log4net have a way to create a RollingFileAppender with composite rolling style where the rolled files always preserves the given extension (.log in my case)?

Example of the format I would like:

MyLog.log

MyLog.2011-04-10.1.log

MyLog.2011-04-10.2.log

MyLog.2011-04-10.3.log

I found this post which says that there is a "PreserveLogFileNameExtension" property, but that it's not included in the official binaries. Is this still the case?

If so: Can anyone explain why this property is still not an offical part of Log4Net? I am a bit sceptical to use a custom build, but maybe I should not be?

I am also curious to know why the default functionality does not preserve the file extension. I do not see why it would gain the user that all the log files have different extensions.

开发者_Go百科

Edit: Got it working by doing this:

1: Downloading and building the log4net source code

2: Applying these patches: https://issues.apache.org/jira/browse/LOG4NET-64

3: Setting PreserveLogFileNameExtension to "true" in the config.


Have you tried these parameters?

<file value="log-files\MyLog" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd'.log'" />
<param name="StaticLogFileName" value="false" />

It will preserve the extension, but will give you a date in every filename like this.

MyLog2011-05-16.log 
MyLog2011-05-17.log 
MyLog2011-05-18.log 
MyLog2011-05-19.log 

Maybe it is possible to combine this with the size rolling?


The situation is unchanged. There is no newer release of log4net. It is quite unclear to me when (if) there will be a new release...

I think you do not need to worry to much about using a custom build. Test your software, if it works it is good enough.

EDIT: There is a new release that should include LOG4NET-64. Of course you can still stick to your custom build.


I'm using this configuration:

<file value="" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd'.log'" />
<staticLogFileName value="false" />

To get filenames like:

  • 20111101.log
  • 20111102.log
  • 20111103.log
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜