Sometimes documentation is plain anoying. I've been using log4j since ... I don't know, maybe 5-6 years? The setup was as simple as dropping a log4j.xml into the class path and using the logger right away.
Log4Net ist not really much more complicated, but it requires a little bit more attention. Here is what you need to start logging via log4net in less than 2 minutes:
log4net.Config.XmlConfigurator.Configure(); once to initialize the log4net stack
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net debug="true"> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net" > <param name="File" value="Debug.log" /> <param name="AppendToFile" value="true" /> <maximumFileSize value="10MB" /> <maxSizeRollBackups value="2" /> <layout type="log4net.Layout.PatternLayout,log4net"> <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n" /> </layout> </appender> <root> <priority value="ALL" /> <appender-ref ref="LogFileAppender" /> </root> </log4net> </configuration>
Here is a pretty elegant way to obtain a logger with the category automatically set to the current class - (there is no equivalent to this in Java by the way - at least not for static fields)
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
The Logfile will be created next to the executable. Oh, and just in the case you did not know, you can use system envoronment variables in the App.config. For instance you could be foolish (or lazy if you prefer) and log directly onto the Windows system drive:
<param name="File" value="${SystemDrive}\Debug.log" />