Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between logger and root level in log4Net?

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?

like image 430
Rocky Singh Avatar asked Jan 04 '11 11:01

Rocky Singh


People also ask

What is root in log4net?

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).

What is level value in log4net?

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.

What are the main components of log4net?

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.


1 Answers

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.

like image 50
Daniel Peñalba Avatar answered Sep 28 '22 05:09

Daniel Peñalba