I'm trying to filter my appender based on the type of exception being logged. Is this possible in log4net?
log4net does not support this directly. You can however quite easily implement your own filter by deriving either from the IFilter
interface or the FilterSkeleton
class (both in log4net.Filter
namespace).
Something like this should do the trick:
public class ExceptionTypeFilter : FilterSkeleton
{
override public FilterDecision Decide(LoggingEvent loggingEvent)
{
var ex = loggingEvent.ExceptionObject as YourExceptionType;
return (ex != null) ? FilterDecision.Accept : FilterDecision.Deny;
}
}
This filter you can then use like a regular filter. For further reference you may look at the source code of the standard log4net filters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With