Search code examples
customizationlog4netfailoverappender

How can I force Log4net from failing silently so that I might implement the FailoverAppender?


Log4j has an appender called the FailoverAppender. This appender allows you to choose a primary appender and as many secondary appenders as you'd like. If the primary appender fails to log, the secondary kicks in and logs. I noticed that Log4Net does not have this type of appender. I know that Log4Net can log in parallel, but I'd much rather have a secondary appender activated and log only if the primary appender fails. What's preventing me from accomplishing this is that Log4Net is a fail-stop logging system. Is there a way to force an exception to be thrown from an appender when logging fails so that I can implement a FailoverAppender? I'm thinking I need to override some public ErrorHandler which implements IErrorHandler. I've been trying to tailor the ForwardingAppender to do what I want, but since each attached appender fails silently, I can't get things to work. Any and all help would be greatly appreciated. If there are examples out there, please point me to them.


Solution

  • So, after reading stuartd's answer, I did a bit more research on implementing IErrorHandler. During that research, I stumbled across the FallbackAppender. I feel a bit foolish now that I've found this. I just thought I'd put this answer out there so others can find the FallbackAppender a lot quicker. Thanks peer and stuartd. I appreciate the responses.