views:

390

answers:

1

Hi Everyone,

I have a problem with Log4Net. Running C# .Net 2.0 Log4Net Ver. Not Sure. How do I check it? Think it's 1.2

It seems to only spawn a new file everytime I restart the web config. Any ideas why my log file isn't rolling over?

<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
                 <maximumFileSize value="10KB" />
                 <maxSizeRollBackups value="-1" />
                 <rollingStyle value="Size" />
                 <appendToFile value="false" /> 
                 <threshold value="ON" />
                 <file value="Log.txt" />
                 <staticLogFileName value="false" />
                 <countDirection value="1" />
                 <layout type="log4net.Layout.PatternLayout">
                 <conversionPattern value="%d [%t] %-5p %c [%x] [%X{auth}] - %m%n" />
                 </layout>
</appender>

Another thing, there appears to be conflicting statements in how appendToFile is used in the documentation provided on the Apache Log4Net website.

First link http://logging.apache.org/log4net/release/config-examples.html

"The appendToFile property is set to false to prevent the appender from overwriting the existing files."

Second link http://logging.apache.org/log4net/release/sdk/log4net.Appender.FileAppender.AppendToFile.html

"If the value is set to false then the file will be overwritten, if it is set to true then the file will be appended to. "

So which is which? In my case, I want my log files to keep spawning new log documents without overwriting existing logs. (The maximumFileSize value is set to 10KB as a test value).

+1  A: 

Change to

<appendToFile value="true" />

The documentation in the config examples (your first link) is incorrect.

Also, this line is wrong:

<threshold value="ON" />

The value should be a valid logging level, e.g. "Debug" or "All"

Matt Howells
Cool, lemme try it out. Get back to you in a bit.
Nai
Sweet, its rolling now. However, its not rolling *correctly*. It seems to spawn 2 new log files everytime the max file size is reached. e.g log.txt.5 and log.txt.5.5 then once those are full, it spawns log.txt.6 and log.txt.6.6. Any idea on this?
Nai
Don't bother, I got it. Was putting my lock type element above the appender *rolls eyes*
Nai