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:
- writing config section for Log4Net in web.config file
- insert logging code in conponents and web page code-behind
- 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.
- 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:
- writing config section for Log4Net in web.config file
- insert logging code in conponents and web page code-behind
- At Global.asax file, under Application_Start event, add "log4net.Config.XmlConfigurator.Configure()" to trigger Log4Net to log stuffs.
- 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.
Technorati tags: microsoft, asp.net, programming, log4net, .net
Comments
Anonymous
June 19, 2007
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.aspxAnonymous
June 20, 2007
You've been kicked (a good thing) - Trackback from DotNetKicks.comAnonymous
January 20, 2008
PingBack from http://websitescripts.247blogging.info/rexiologymsdn-configure-log4net-for-aspnet-20-web-application/Anonymous
December 29, 2009
Thank you so much. Your post helped me a lot.