I just came across the two sections in log4net configiurations:
<logger name="File">
<level value="All" />
</logger>
<root>
<level value="INFO" />
</root>
May I know what is the difference of specifying levels at logger and root tags? What is the difference between them?
This way the loggers create a tree and the root logger is simply the root of that tree (in the example Foo is a child of the root logger). This hiearchy allows for some interesting configuration applications (e.g. disable/enable logging for an entire sub system of your application).
log4net offers the following log levels, in increasing order of priority: ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF. The ALL level logs everything and the OFF level logs nothing. You can assign these log levels to each logger in your configuration file.
Log4net has three main components: loggers, appenders and layouts. These three types of components work together to enable developers to log messages according to message type and level, and to control at runtime how these messages are formatted and where they are reported.
root
means all logs in the application, and logger
allows to refer to a certain kind of log. Using them you can change the log configuration only for cetain logs. Look your sample with comments:
<!-- Set root logger level to INFO-->
<root>
<level value="INFO" />
</root>
<!-- Print only messages of level WARN or above in the package "File" -->
<logger name="File">
<level value="WARN" />
</logger>
In this sample all logs are to INFO, and the the log of the type "File" (or named File) is WARN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With