logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gulati, Jay, GCM" <Jay.Gul...@rbsgc.com>
Subject Reading config in business layer
Date Fri, 15 Jun 2007 14:45:29 GMT
Hi,

I have asp application  and writing new module in asp.net; how can I use
config settings for appender?  I like to use rollfileappender.
I module is class library and tried to add app.config and app.log4net
but it's not exe or web so can't read the configuration.
So my question is how to set xmlconfigurator to read config file?

Here is my test class and config file (simple)
using System;
using System.Collections.Generic;
using System.Text;

using log4net;
using log4net.Config;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace busLayer
{
    public class Class1
    {
        private static readonly ILog log =
LogManager.GetLogger(typeof(Class1));

        public Class1()
        {
            log4net.Config.BasicConfigurator.Configure(new
log4net.Appender.RollingFileAppender());
        }

        public void MyLog(string message)
        {
            log.Debug(message);
        }
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
      <file value="log.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="100KB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
      </layout>
    </appender>

    <root>
      <level value="INFO" />
      <appender-ref ref="RollingFileAppender" />
    </root>
  </log4net>
</configuration>

Thank You,

-Jay Gulati



Mime
View raw message