tags:

views:

967

answers:

2

When I compiled my application in release mode, I found that the Log4Net still logs debug information; any idea how to fix this?

This is my App.Config file:

<configuration>

  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
  </configSections>


  <log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="LogFileAppender" />
    </root>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
      <param name="File" value="C:\Documents and Settings\test\Application Data\Log.txt" />
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} - %m%n" />
      </layout>
    </appender>
  </log4net>

Did I miss anything?

+4  A: 

There's nothing in your App.Config file to tell log4net to do things differently in release or debug mode. If you want logging to be different between the two builds, you have to change your configuration file between the two builds.

Your best bet is probably to create one App.Config for Release, one for Debug, and then follow the advice in the StackOverflow question:

NOTE: The difference between your release and debug App.Config will be the following line in the debug version

<level value="DEBUG" />

versus the following line in the release version (or of course you could choose ERROR or FATAL if you want):

<level value="INFO" />
Eddie
+3  A: 

Maybe try something like this instead? Set to whatever minimum level you want to receive.

<level value="WARN" />
Aaron