Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net, whats up with this config

log4net is reporting:

No appenders could be found for logger log4net: Logger: Please initialize the log4net system properly.

I have a stand alone log4net config file:

<!--?xml version="1.0"?-->
<configuration>
  <configsections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" />
  </configsections>
  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="c:\temp\log.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="5MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>


  </log4net>
</configuration>

..and this app start code

private static ILog logger;
protected void Application_Start(object sender, EventArgs e)
{
    ////This tells log4net where to go and look for its configuration file and also to watch it for any changes
    log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Config\Moogle\Log4Net.config"));
    logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
    logger.Debug("Application_Start Fired");
like image 937
jenson-button-event Avatar asked Jan 20 '12 10:01

jenson-button-event


People also ask

What is log4net config?

The log4net configuration can be configured using assembly-level attributes rather than specified programmatically. If specified, this is the filename of the configuration file to use with the XmlConfigurator. This file path is relative to the application base directory (AppDomain. CurrentDomain.

Is log4net using Log4j?

Log4j is a very popular logging framework for Java developers, used by most Java applications. It has been ported to other programming languages including log4perl, log4php, log4net, and log4r.

Where is log4net config?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.


1 Answers

You have only defined an appender. You also need to define a root logger and a logger to use the appender (they can be the same logger if you only need one). Add the following root element below to your log4net config.

<root>
  <level value="DEBUG" />
  <appender-ref ref="RollingLogFileAppender" />
</root>
like image 158
gregwhitaker Avatar answered Oct 21 '22 11:10

gregwhitaker