Log4net configuration

I always forget how to configure log4net to enable it’s powerful logging capabilities. So here’s how:

For web applications: in your global.aspx file, when the application starts, add this line: XmlConfiguration.Configure();

For desktop applications add the same line in the main function.


protected void Application_Start()
In  web.config / app.config add this configuration:
Declare the section in the section configuration
<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net” />
Configure the logger for file logging:
<appender name=”LogFileAppender” type=”log4net.Appender.FileAppender”>
<param name=”File” value=”Logs\\Log4Net.log” />
<layout type=”log4net.Layout.PatternLayout”>
<param name=”ConversionPattern” value=”%d [%t] %-5p %c %m%n” />
<logger name=”File”>
<level value=”All” />
<appender-ref ref=”LogFileAppender” />
That’s it, hope this helps!
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Log4net configuration

  1. Thanks for the interesting information. Subscribe to rss

Leave a Reply to Web development Moldova Cancel reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>