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
  • 66,195
  • 14
  • 128
  • 158
John
  • 3,853
  • 20
  • 69
  • 146

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.
  • 462
  • 3
  • 15
hutchonoid
  • 32,257
  • 14
  • 95
  • 102