Hi Devin!

I was trying to get log4net working on my ASP.NET 2.0 application yesterday. I am using the Web.Config file instead of a separate config file.

I created a AssemblyInfo.cs inside App_Code. This file contains only one line:

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

I dont have a Globa.asax file.

To test logging place this in Page_Load:

log4net.ILog log = log4net.LogManager.GetLogger("TestLogger");
log.Debug("Hello world");


In my Web.Config I have:

<?xml version="1.0"?>
<configuration>
   <configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net-net-1.0" />
   </configSections>

   <log4net>
<appender name="GlobalLogFile" type="log4net.Appender.RollingFileAppender">
           <file value="c:/LogFiles/Global.log" />
           <appendToFile value="true" />
           <rollingStyle value="Size" />
           <maxSizeRollBackups value="-1" />
           <maximumFileSize value="25MB" />
           <layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
           </layout>
       </appender>

       <root>
           <level value="DEBUG" />
           <appender-ref ref="GlobalLogFile" />
       </root>
   </log4net>
</configuration>

Best Regards
*Morten Andersen*
Developer
Vianett AS <http://www.vianett.no/> | [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> | Office: +47 69 20 69 74 <callto://+4769206974> | Skype: mortander <callto://mortander>



Devin Smith wrote:
Hi,

I've spent a number of hours trying to get log4net to log something in
an ASP.NET project but have not gotten anywhere. Hopefully someone can
tell me what's going on here.

In the AssemblyInfo.cs file for my main site I have:

[assembly: log4net.Config.Repository("SiteCore")]
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",
Watch=true)]

In Global.ascx.cs:

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

and inside Application_Start:

public void Application_Start(object sender, EventArgs e)
{
                log4net.Config.XmlConfigurator.Configure();
                log.Info("Hello World, I am a logger");
}

Now because I have the settings above in my AssemblyInfo.cs I need a
seperate config file (well according to the mailing list, and many
blog sites). Inside the bin of my ASP.net project I have a
SiteCore.dll.log4net file that contains the following:

<?xml version="1.0" encoding="utf-8" ?>
<!-- This section contains the log4net configuration settings -->
<log4net>
        <!-- Define some output appenders -->     
        <appender name="RollingLogFileAppender"
                  type="log4net.Appender.RollingFileAppender,log4net">
           <param name="File"
              value="C:\\Inetpub\\wwwroot\\test1\\LogFiles\\mylog.txt"/>
           <param name="AppendToFile" value="true"/>
        
        <param name="MaxSizeRollBackups" value="10"/>
        <param name="MaximumFileSize" value="5MB"/>
        <param name="RollingStyle" value="Size"/>
        <param name="StaticLogFileName" value="true"/>
        <layout type="log4net.Layout.PatternLayout,log4net">
                <param name="ConversionPattern"
                value="%d [%t] %-5p %c [%x] - %m%n"/>
        </layout>
        </appender>

        <!-- Setup the root category, add the appenders and set the default
priority -->
        <root>
                <level value="DEBUG" />
                <appender-ref ref="RollingLogFileAppender" />
        </root>
</log4net>

Now, I checked that LogFiles is writeable by ASPNET and I also created
a 0 byte mylog.txt and made it writeable by ASPNET as well.

I'm not sure what i'm doing wrong but any help is appreciated.

Thanks,

Devin

Reply via email to