Welcome to MSDN Blogs Sign in | Join | Help

Rexiology@MSDN

Nothing but Microsoft Technologies...
Configure Log4Net for ASP.NET 2.0 Web Application...

Just encountered this problem right now and quickly write the solution here. Should be an old info since ASP.NET 2.0 had been out for a while.

The problem is that I want to use Log4Net on a testing web application to get some log data for analysis. I just downloaded the latest version of Log4Net and followed the way I used in previous projects which was an ASP.NET 1.1 web application,  trying to get Log4Net to run in an ASP.Net 2.0 web app. And it's not running as expected.

the steps to let Log4Net run in ASP.Net 1.1 are:

  1. writing config section for Log4Net in web.config file
  2. insert logging code in conponents and web page code-behind
  3. At website's AssemblyInfo.cs or .vb file, add "<Assembly: log4net.Config.DOMConfigurator(Watch:=True)>" for VB.net or "[assembly: log4net.Config.XmlConfigurator(Watch=true)]" for C# to enable Log4Net to Log stuffs.
  4. compile the web application and run.

By searching and refering the posts here and here and here, comes out that the configuration way in ASP.NET 2.0 is little bit different, as follows:

  1. writing config section for Log4Net in web.config file
  2. insert logging code in conponents and web page code-behind
  3. At Global.asax file, under Application_Start event, add "log4net.Config.XmlConfigurator.Configure()" to trigger Log4Net to log stuffs.
  4. compile the web application and run.

By doing the settings above, Log4Net started to output logs in my ASP.Net 2.0 application.

just one more thing to notice, remember to enable the write permission to "ASPNET" and/or "NETWORK SERVICE" accounts if you still can not get the log file by doing above settings. it may be the file writing permission problems.

FYI.

Posted: Tuesday, June 19, 2007 10:39 PM by rextangtw

Comments

alikl said:

Consider moving to built-in ASP.NET 2.0 healthmonitoring to capture log data for analysis

http://blogs.msdn.com/alikl/archive/2007/05/02/asp-net-health-monitoring-means-logging-and-auditing.aspx

# June 19, 2007 9:59 AM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# June 20, 2007 10:00 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker