Alex Rivera | Logout

log4net with ASP.NET 3.5 problems

Asked 2008-10-22T03:41:21.697
13

I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the first time I've tried to use log4net, I feel like I'm missing a piece of the puzzle.

My project references the log4net assembly, and as far as I can tell, it is being deployed successfully on my server.

My web.config contains the following:

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

  <log4net>
    <appender name="InfoAppender" type="log4net.Appender.FileAppender">
      <file value="..\..\logs\\InfoLog.html" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern
          value="%d [%t] %-5p %c [%x] - %m%n" />
      </layout>
    </appender>
    <logger name="_Default">
      <level value="INFO" />
      <appender-ref ref="InfoAppender" />
    </logger>
  </log4net>

I'm using the following code to test the logger:

using log4net;
using log4net.Config;

public partial class _Default : System.Web.UI.Page
{
    private static readonly ILog log = LogManager.GetLogger("_Default");

    protected void Page_Load(object sender, EventArgs e)
    {
        log.Info("Hello logging world!");
    }
}

In my Global.asax, I'm doing the following:

void Application_Start(object sender, EventArgs e) 
{
    log4net.Config.XmlConfigurator.Configure();
}

At this point, I can't think of what else I might be doing wrong. The directory I'm trying to store the log in is writable, and even if I try different directories I get the same result: no file, no logs.

Any suggestions? :-)


Edit: I've tried several different formats for the path & name of the log file, some of which include

Edit
Report

1 Answer

1

I don't have the Global.asx to run in .net 3.5

this is my code... I configure the log4net in a separate file log4net.config

// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

//My Web Services class name
private static readonly log4net.ILog log = log4net.LogManager.GetLogger("Service1");
answered 2010-10-05T03:08:26.293

Your Answer