2
votes

Given two appenders: A1, A2 and multiple loggers one of which is L1

Is it possible to configure log4net such that:

A1 gets DEBUG and above from all loggers except L1, for which it gets INFO and above
A2 gets DEBUG and above from all loggers

I have looked at appender threshold, filters, and every other configuration combination I can think of but none of them seem to accomplish the above.

2

2 Answers

1
votes

You could do the following:

  1. Define your two appenders (A1, A2) without any filter
  2. Create a BufferingForwardingAppender, that forwards to A1 and filters on level >= INFO
  3. Create a BufferingForwardingAppender, that forwards to A2 (no filter or >= DEBUG)
  4. Configure the root logger to use appenders A1, A2
  5. Configure the L1 logger to not inherit appenders (additivity = false); reference the two BufferingForwardingAppender instead

I did not test it, but I do not see why this would not work.

0
votes

According to the docs:

Filters form a chain that the event has to pass through. Any filter along the way can accept the event and stop processing, deny the event and stop processing, or allow the event on to the next filter. If the event gets to the end of the filter chain without being denied it is implicitly accepted and will be logged.

So it seems that something like this would work (untested pseudo-code):

A1
    Level >= INFO:  Accept
    Logger == L1: Deny
    Level >= DEBUG: Accept
    DenyAll

A2
    Level >= DEBUG: Accept