(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:
<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” />
</layout>
</appender>
<!– Default configuration–>
<root>
<level value=”INFO” />
<appender-ref ref=”ConsoleAppender” />
</root>
<!– Overriden configuration by class name –>
<category name=”NHibernate”>
<level value=”Error” />
</category>
<category name=”OrderSystem.UI”>
<level value=”ALL” />
</category>
<category name=”OrderSystem.DataAccessLayer”>
<level value=”ALL” />
</category>
<category name=”OrderSystem.Objects”>
<level value=”ALL” />
</category>
</log4net>
Step 3: Pickup the log4net.config file. I added this to the bottom of my OrderSystem.UI’s AssemblyInfo.cs file.
Step 4: In any class – Import the namespace.
Step 5: In any class – Get the logger instance.
Step 6: In any class – Use it.
VOILA, now you can configure logging with an external configuration file.
NLog Dawg, NLog.
Sorry man, I came from a log4j background.
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.