0
votes

Hello i am using Log4Net in Console APP

Here is configuration in Assembly File

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

Below is log4net.config

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <log4net>
    <appender name="InfoRollingLogFileAppender"

    type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="WarningLogger.txt" />
      <param name="AppendToFile" value="true" />
      <param name="MaxSizeRollBackups" value="10" />
      <param name="MaximumFileSize" value="10240KB" />
      <param name="RollingStyle" value="Size" />
      <param name="StaticLogFileName" value="true" />
      <param name="Threshold" value="DEBUG"/>
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%p [%d{dd MMM HH:mm:ss}][%l]- %m%n" />
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="WARN" />
        <levelMax value="WARN" />
      </filter>
    </appender>
    <root>
      <level value="debug" />
      <appender-ref ref="InfoRollingLogFileAppender" />
      <appender-ref ref="ErrorRollingLogFileAppender" />
    </root>
  </log4net>
</configuration>

For Initializing log4net i am using following configuration.

  private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

This things perfectly work in Debug mode. Same configuration is not working in release mode.

Let me know if any solutions

2

2 Answers

0
votes

When you static method initializes the is no GetCurrentMethod().DeclaringType. That is probably why it does not work in release mode.

0
votes

Got it resolved by adding up configuration on start up file or Program file in console .

 XmlConfigurator.Configure(new FileInfo(ConfigurationManager.AppSettings["log4net-config-file"]));