Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognized configuration section log4net

I have this code in web.config:

<log4net>
  <root>
    <level value="ALL" />
    <appender-ref ref="LogFileAppender" />
  </root>
  <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
    <param name="File" value="D:\logFileFaculty.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="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
  </appender>
</log4net>

And I have downloaded log4net.dll and placed it in Bin Folder.

In one of My aspx.cs pages I have added this code:

using log4net;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]


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

But it's giving error as Unrecognized configuration section log4net.

like image 931
Shreyas Achar Avatar asked Oct 17 '13 06:10

Shreyas Achar


2 Answers

You need to declare the log4net section:

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

Take a closer look at the documentation which explains the necessary things to do.

like image 62
Darin Dimitrov Avatar answered Nov 20 '22 05:11

Darin Dimitrov


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

add to your app.config file

like image 23
lambex Avatar answered Nov 20 '22 07:11

lambex