Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I setup log4net to log certain events if they occur/happen more than N times per time span?

Basically, I would like to be able to log events such as "HTTP timeouts" in my application only if they happen more than 100 times per minute (for example).

Is there any way to configure log4net to handle such a task?

Thanks in advance,

like image 376
Aviv Stern Avatar asked Dec 05 '25 11:12

Aviv Stern


1 Answers

No, you cannot configure it to behave that way.

But, you can achieve this fairly easily by writing your own, custom Appender. Simply inherit from AppenderSkeleton, and override the Append method with your own logic (passing the event parameter to the base implementation as needed).

Any public property in your class can will be automatically loaded by log4net from the configuration file, so you can also specify the threshold rate this way.

like image 185
Groo Avatar answered Dec 07 '25 01:12

Groo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!