multi log4net instances using different configurations from the same config file

274 Views Asked by At

I am writing an application that will require 2 different loggers, each logging in a totally different way. When I create each instance of the log4net logger how can I get it to read from its own config section within the same app.config file. Is this possible as all I have seen so far is it taking the default

1

There are 1 best solutions below

0
On BEST ANSWER

You can log two or more things independently without using separate config files.

LogManager.GetLogger("Log1")
LogManager.GetLogger("Log2")

Then in your config file you can create them like this

<logger name="Log1" additivity="false">
  <level value="INFO" />
  <appender-ref ref="LogFileAppender1" />
</logger>

<logger name="LOg2" additivity="false">
  <level value="INFO" />
  <appender-ref ref="LogFileAppender2" />
</logger>

By selecting additivity as false then they will log separately. You can then populate their appenders to write the info as needed.