Radek Strugalski
Radek Strugalski

Reputation: 568

How to disable log4net from catching all exceptions?

I wanted to implement fake appender that throws an exception when logging particular text. Apparently with log4net it is extremely difficult. I tried to implement my own Appender derived from AppenderSkeleton. Also changed ErrorHandler to one that is rethrowing exceptions. But nothing stops log4net from catching all exceptions.

Is there a way to stop log4net from doing it? Preferably programmatically.

Thanks

Upvotes: 1

Views: 338

Answers (1)

Peter
Peter

Reputation: 27944

You can't do this. Log4net does not throw exceptions by design. By design log4net does not interact with the running program.

Is log4net a reliable logging system? No. log4net is not reliable. It is a best-effort and fail-stop logging system. By fail-stop, we mean that log4net will not throw unexpected exceptions at run-time potentially causing your application to crash. If for any reason, log4net throws an uncaught exception (except for ArgumentException and ArgumentNullException which may be thrown), please send an email to the [email protected] mailing list. Uncaught exceptions are handled as serious bugs requiring immediate attention. Moreover, log4net will not revert to System.Console.Out or System.Console.Error when its designated output stream is not opened, is not writable or becomes full. This avoids corrupting an otherwise working program by flooding the user's terminal because logging fails. However, log4net will output a single message to System.Console.Error and System.Diagnostics.Trace indicating that logging can not be performed.

Upvotes: 2

Related Questions