Subtopic: QUICKLY Get log4net Setup.

(This is a subtopic of the Learning NHibernate by Example (Small).)

It took me a while to get used to log4net version 1.2.10. Here’s my attempt at a quick crash course on what I consider the basics of log4net.

Step 1: Download and reference it, derrr.

Step 2: Create a log4net.config file. I put mine in the OrderSystem.UI section, in the same location as the app.config of the startup application.

Here is mine, for now:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<log4net debug=”false”>

<!– Console Appender declaration –>
<appender name=”ConsoleAppender” type=”log4net.Appender.ConsoleAppender” >
<layout type=”log4net.Layout.PatternLayout”>
<param name=”ConversionPattern” value=”%-5p : %m%n” />

<!– Default configuration–>
<level value=”INFO” />
<appender-ref ref=”ConsoleAppender” />

<!– Overriden configuration by class name –>
<category name=”NHibernate”>
<level value=”Error” />
<category name=”OrderSystem.UI”>
<level value=”ALL” />
<category name=”OrderSystem.DataAccessLayer”>
<level value=”ALL” />
<category name=”OrderSystem.Objects”>
<level value=”ALL” />


Step 3: Pickup the log4net.config file. I added this to the bottom of my OrderSystem.UI’s AssemblyInfo.cs file.

[assembly: log4net.Config.XmlConfigurator(ConfigFile = “log4net.config”, Watch = true)]

Step 4: In any class – Import the namespace.

using log4net;

Step 5: In any class – Get the logger instance.

private static readonly ILog log = LogManager.GetLogger(typeof (Program));

Step 6: In any class – Use it.


VOILA, now you can configure logging with an external configuration file.

3 thoughts on “Subtopic: QUICKLY Get log4net Setup.

  1. Dude Log4J is 50 times easier to use than this log4net stuff. I’m trying to get it to work so I can get my NHibernate logs, and it’s a hobag.

    NLog, all up in dat B.

Leave a Reply

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

Solve this: Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.