1

Using log4net to store text in file. from

http://sadi02.wordpress.com/2008/06/29/log4net-tutorial-in-c-net-how-can-i-show-log-in-a-file/

In the appsettings file:

 <param name="File" value="C:\Try\logger\logger\bin\Debug\log.txt" />

is used to create the file. Problem is the file will already exist from previous runs; how can I add additional info to the filename e.g.

 <param name="File" 
        value="C:\Try\logger\logger\bin\Debug\log + "Monday" + .txt" />

Here Monday flags saying it is missing required whitespace?

UPDATE *Thanks for the duplicate Ive used it to add:*

  <param name="DatePattern" value="dd.MM.yyyy'.log'" />
  <param name="File" 
         value="C:\Try\logger\logger\bin\Debug\log + DatePattern + .txt" />  

but now the file is saved as

log + DatePattern + .txt

why wont it save the actual date?

stuartd
  • 70,509
  • 14
  • 132
  • 163
John
  • 3,965
  • 21
  • 77
  • 163

1 Answers1

2

You can use log4net.Util.PatternString to do this, in your case do the following:

 <file type="log4net.Util.PatternString" value="C:\Try\logger\logger\bin\Debug\log%date{dd}.txt" />

For further info please refer to the documentation:

Documentation of log4net.Util.PatternString class

lars k.
  • 562
  • 4
  • 18
hutchonoid
  • 32,982
  • 15
  • 99
  • 104