Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lossy logging, also get some messages after an error?

Lossy logging in log4net is great to get the details of events leading to an error with minimal performance-loss. However it would often be interesting to also log a few messages after the error to verify that the system handled it as planned. How can it be done?

like image 452
Grastveit Avatar asked Feb 01 '26 12:02

Grastveit


1 Answers

I would write a custom version of the BufferingForwardAppender, which would log a configurable number of message after an error. Basically you turn off "being lossy" after an error for a while and forward all messages directly.

Note: Make sure that the appender flushes the messages immediately when an error is logged because you cannot be sure that there will be other messages after the error.

like image 81
Stefan Egli Avatar answered Feb 03 '26 10:02

Stefan Egli