4

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.

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.

Community
  • 1
  • 1
Knut Marius
  • 1,588
  • 18
  • 40

3 Answers3

4

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?

Unger
  • 41
  • 1
2

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.

Stefan Egli
  • 17,398
  • 3
  • 54
  • 75
  • Thanks for the quick reply! I made a custom build, and set the "PreserveLogFileNameExtension" property to true. That seemed to work for the size rolling, but not the date. It now rolls to "MyLog.1.log", as desired, but when it rolls on date I get "MyLog.1.log04-11-2001" which is much the same I had before. Any more hints to how I can get "MyLog.1.04-11-2011.log"? I tried using the trick with , but in combination with PreserveLogFileNameExtension it did not work; for some reason it only kept the last log file when it rolled date.. – Knut Marius Apr 11 '11 at 12:55
  • maybe the feature is not implemented properly... If I were you I would try to fix it myself in the source code (if I really needed it) – Stefan Egli Apr 11 '11 at 13:29
  • When I applied the patches from this page, it worked as I wanted it to! https://issues.apache.org/jira/browse/LOG4NET-64 – Knut Marius Apr 12 '11 at 07:51
0

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
ZogStriP
  • 567
  • 1
  • 9
  • 25