You can create multiple appenders and decorate them with Log4Net Filters to include the specific logger or loggers you want.
The particular filter you want is the LoggerMatchFilter — you provide a string to be matched against the logger name via string.StartsWith()
. Matching logger(s) are either included or excluded as a as a data source for the appender. That is why the log4net recommended naming convention for loggers is to have each class instantiate it's own logger instancej, name it with the fully qualified type name of the class (Type.FullName
):
class Widget
{
static ILogger log = LogManager.GetLogger(typeof(Widget)) ;
. . .
}
That creates a logger whose name is the fully qualified name of the class. Note that the logger doesn't have to be a static property: the logger can be instantiated dynamically instead of statically: only once instance of a logger with a given name is ever created.
The notion is that the app as a whole could log only high level event. If there's a problem, while the app is running, you can tweak the log4net config to dial in lower level logging all the way down to the class level.
More on log4net configuration at http://logging.apache.org/log4net/release/manual/configuration.html
Here's a little tutorial on filters: http://www.beefycode.com/post/log4net-tutorial-pt-7-filters.aspx