Is it possible to wildcard logger names in log4net configuration?

You can just specify part of a namespace so it will apply to all messages within that namespace (including nested).

Here is the example I often use:

    <level value="FATAL" />
    <appender-ref ref="RollingFile" />

  <logger name="MyCompany.Web" >
    <level value="WARN" />
    <appender-ref ref="WebErrors" />

  <!-- Will log all FATALs from NHibernate, including NHibernate.SQL and all the nested -->
  <logger name="NHibernate" >
    <level value="FATAL" />

Additionally I would recommend to read the manual. It provides a lot of explanation. For example you can read about Logger Hierarchy. Here is the quote from there:

A logger is said to be an ancestor of
another logger if its name followed by
a dot is a prefix of the descendant
logger name. A logger is said to be a
parent of a child logger if there are
no ancestors between itself and the
descendant logger. The hierarchy works
very much in the same way as the
namespace and class hierarchy in .NET.

and also:

Level Inheritance:
The inherited level for a given logger X, is equal to the first
non-null level in the logger
hierarchy, starting at X and
proceeding upwards in the hierarchy
towards the root logger.

Leave a Comment