There are two ways of configuring and using log4net. First one is when I can configure my own appender and associated logger:
<!-- language: xml -->
<appender name="myLogAppender" type="log4net.Appender.RollingFileAppender" >
<file value="Logs\myLog.log" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level - %message%n" />
</layout>
</appender>
<logger name="myLog">
<level value="All"></level>
<appender-ref ref="myLogAppender" />
</logger>
And then when I want to write something in log, I can do the following:
ILog log = LogManager.GetLogger("myLog");
log.Info("message");
Another way to use it is to configure root to be as detailed as I want:
<!-- language: xml -->
<root>
<level value="Error" />
<appender-ref ref="myLogAppender" />
</root>
And in this case I can log messages like this:
ILog log = LogManager.GetLogger(typeof(Bar));
log.Info("message");
The benefits of second approach is that you can enable or disable some messages on the fly. But the problem is that I'm developing in EPiServer CMS and it has its own logging system that uses log4net and if I enable info logging at root level, then a lot of system logs will be written.
How do you use log4net? Each part of a system writes in its own logger, or everything is written in default logger, and configuration decides what to do next?