Aviv Stern
Aviv Stern

Reputation: 31

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,

Upvotes: 3

Views: 214

Answers (2)

vgru
vgru

Reputation: 51284

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.

Upvotes: 4

Related Questions