There are two ways to configure and use log4net. Firstly, when can I configure my own appender and its associated log:
<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 a journal, I can do the following:
ILog log = LogManager.GetLogger("myLog"); log.Info("message");
Another way to use this is to configure root the way I want:
<root> <level value="Error" /> <appender-ref ref="myLogAppender" /> </root>
And in this case, I can record the following messages:
ILog log = LogManager.GetLogger(typeof(Bar)); log.Info("message");
The advantages of the second approach are that you can enable or disable some messages on the fly. But the problem is that I am developing on EPiServer CMS and it has its own logging system that uses log4net, and if I turn on root level logging then a lot of system logs will be written.
How do you use log4net? Each part of the system writes to its own log, or everything is written to the registrar by default, and the configuration decides what to do next?
Sly Aug 17 2018-11-11T00: 00Z
source share