Cole W
Cole W

Reputation: 15303

How to configure multiple loggers in dll

I'm new to log4net and I'm not quite sure how to set up my app.config correctly when there are multiple loggers in a dll. Well I do but I'm wondering if there is an easier way when there are 10-20 different loggers. It may also be that I just don't understand this.

Ok so let's say the dll uses the following loggers (it's actually about 20 different statements like this):

private static readonly ILog log = LogManager.GetLogger(typeof(XmlConfiguration));
private static readonly ILog log = LogManager.GetLogger(typeof(ClassValidator));

Does this mean I need to do something like this in my app.config (I have omitted appenders for brevity)?

<logger name="XmlConfiguration" additivity="false">
  <level value="DEBUG"/>
  <appender-ref ref="FileLog"/>
</logger>

<logger name="ClassValidator" additivity="false">
  <level value="DEBUG"/>
  <appender-ref ref="FileLog"/>
</logger>

Can I configure it somehow such that each logger exposed by a particular dll or partial namespace (loggers in dll are under several different namespaces but have a common root namespace) all go to the same logging source (file, console etc)?

Upvotes: 1

Views: 458

Answers (1)

Dipti Mehta
Dipti Mehta

Reputation: 547

Yes, you are correct. You can set different login levels for different dlls by configuring multiple loggers :

Here is an example i have used successfully :

<!-- ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF -->
<root>
  <level value="Error"/>
  <appender-ref ref="RollingLogFileAppender"/>
</root>

<logger name="NHibernate">
  <level value="ERROR" />
</logger>

Upvotes: 2

Related Questions