Lasantha PW

Lasantha PW

  • NA
  • 213
  • 156.5k

Log4net

Apr 8 2011 1:22 AM

Hi Everyone

In my .Net solution I have a class library project and an ASP.net project. This is how I use log4net in the Class library

 

AssemblyInfo.cs

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

 

App.config

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <configSections>

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" />

  </configSections>

 

  <!-- Log4net Logging Setup -->

  <log4net debug="false">

    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">

      <param name="File" value="C:\\test.log"/>

      <param name="AppendToFile" value="true"/>

      <maxSizeRollBackups value="10"/>

      <datePattern value="yyyy-MM-dd"/>

      <rollingStyle value="Date"/>

      <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>

      <layout type="log4net.Layout.PatternLayout">

        <header value="Date | Level | SessionID | Logger | Message | &#xA;"/>

        <param name="ConversionPattern" value="%date{ABSOLUTE}| %-5p | %-30logger| %m|%n"/>

      </layout>

    </appender>

    <root>

      <priority value="DEBUG"/>

      <appender-ref ref="RollingLogFileAppender"/>

    </root>

  </log4net>

</configuration

 

 

 

 

Logger class

private static readonly ILog logger =

                  LogManager.GetLogger(typeof(Class1));

log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("App.config"));

                  logger.Debug("Here is a debug log.");

                  logger.Info("... and an Info log.");

                  logger.Warn("... and a warning.");

                  logger.Error("... and an error.");

                  logger.Fatal("... and a fatal error.");

 

But didn't log anything in log file. Could you please help me figure out what I am doing wrong?

 


Answers (1)