Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off Debug Logging during Release in Log4net

Tags:

log4net

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?

like image 735
Graviton Avatar asked Dec 02 '22 07:12

Graviton


1 Answers

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:

  • Deploy an app.config based on build configuration

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" />
like image 179
Eddie Avatar answered Dec 06 '22 04:12

Eddie