I am just getting into using log4net, and for the most part I like what I see.  It works with .NET 2.0, but it has a couple of gotchas that do not seem to be documented anywhere.  Here they are:

For ASP.NET 2.0 web sites, since there is no longer an AssemblyInfo.cs file, enable log4net by telling it to search the Web.config file for the appender configuration inside Global.asax:

protected void Application_Start(Object sender, EventArgs e) {
	log4net.Config.DOMConfigurator.Configure();
}

For .NET 2.0 class libraries, test projects  and applications, call this same method where your application starts, or in some static method for your test project or class library.

5 thoughts on “Enabling log4net in .NET 2.0”
  1. hi, do u know how to use log4net on a c# program? I’m trying to make a GUI application to analyze log files…and I think lo4net would really help me in this case

  2. Just put the Configure method call in your C# program somewhere before you start logging. If that doesn’t do it for you, if you can give more detail about what you’re doing perhaps we can figure something out.

  3. I have been using log4net.Config.XmlConfigurator.Configure(); for a while. Not sure which one is the right one. Good post BTW 🙂

Comments are closed.