try...catch...finally...bloggg....: using Log4net in ASP.NET application

try...catch...finally...bloggg....

Monday, April 11, 2005

using Log4net in ASP.NET application

I tried setting up the logging for our webapplication using Log4net. I looked thro the examples and read some blogs on how difficult it is to setup the whole logging because of the lack of documentation. Read thro these blogs to see the info posted by different people

http://tom.gilki.org/programming/net/120604/
Ryans work blog
http://geekswithblogs.net/flanakin/archive/2004/08/30/10418.aspx

These are the steps which helped me get the logging setup
1.[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net", Watch=true] this line must be added to the global.asax.cs file
1 // Load the configuration from the 'JobBoard.UI.dll.log4net' file
2 [assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",
3 Watch=true)]
4 namespace xxxxxx
5 {

2. The name of the configuration file should be the name of the dll into which the global.asax.cs file is getting compiled with an extension of log4net. For eg if your dll generated is foo.dll then your configuration goes into foo.dll.log4net.
3. The configuration file should be located in the application root folder not in the bin folder.
4. Check the permissions on the folder you are logging the aspnet user account should have write permissions.

below is the sample configuration file I used for appending to the File and to Trace.
1 <?xml version="1.0" encoding="utf-8" ?>
2 <log4net debug="false">
3 <appender name="LogFileAppender"
4 type="log4net.Appender.FileAppender" >
5 <file value="c:\\temp\\webapp-log.txt" />
6 <appendToFile value="true" />
7 <layout type="log4net.Layout.PatternLayout">
8 <conversionPattern value="%date [%thread] %-5level %logger
9 [%ndc] - %message%newline" />
10 </layout>
11 </appender>
12 <appender name="HttpTraceAppender"
13 type="log4net.Appender.AspNetTraceAppender" >
14 <layout type="log4net.Layout.PatternLayout">
15 <conversionPattern value="%date [%thread] %-5level %logger
16 [%ndc] - %message%newline" />
17 </layout>
18 </appender>
19 <root>
20 <level value="DEBUG" />
21 <appender-ref ref="LogFileAppender" />
22 <appender-ref ref="HttpTraceAppender" />
23 </root>
24 </log4net>
25

0 Comments:

Post a Comment

<< Home


·