.net – Log4Net Not Rolling

.net-2.0log4netnet

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).

Best Answer

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"

Related Topic