Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4Net: Multiple loggers

I have the following log4net configuration:

<log4net>
  <appender name="A1" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="C:\path1.log" />
  </appender>

  <appender name="A2" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="C:\path2.log" />
  </appender>

  <logger name="A1Logger">
    <level value="ALL" />
    <appender-ref ref="A1" />
  </logger>

  <logger name="A2Logger">
    <level value="ALL" />
    <appender-ref ref="A2" />
  </logger>

</log4net>

and then in code I do the following:

var logger1 = LogManager.GetLogger("A1Logger");
var logger2 = LogManager.GetLogger("A2Logger");

but both log to the same file C:\path1.log.

What am I doing wrong?

like image 247
Román Avatar asked Aug 12 '10 17:08

Román


People also ask

What is additivity in log4net?

Logger. Additivity Property. Gets or sets a value indicating if child loggers inherit their parent's appenders.

Where are log4net logs stored?

The log4net. config file is located in the \Enterprise7\bin\ directory and is the configuration file for the log4net logging application.


2 Answers

Add the debug="true" attribute to the <log4net> element, my guess is that it is the missing <root> element that causes problems. You should always include the <root /> logger element.

like image 165
Peter Lillevold Avatar answered Oct 21 '22 23:10

Peter Lillevold


Seems that it was a weird debugging error. Right now it doesn't reproduce. My apologies.

like image 35
Román Avatar answered Oct 21 '22 23:10

Román