.Net 4
I am using log4net in a windows service. The service has an internal timer and is scheduled to runs every 30 minutes. I would like to receive an email with all the logging activity every time the processing is complete. The only examples I found are with the smtp appender, but that sends an email everytime something is logged which is not what I need.
I would think this is a normal use case, but can’t find any relevant examples…
Thanks for any help!
I don’t think this is a standard use of it, as the SMTPAppender is mostly designed to be used to trigger on errors (which should be rare). Here’s the description of the appender:
Looking at the documentation for SMTPAppender, I see that one of the properties is a class which evaluates the input message, and decides whether to trigger the e-mail to be sent.
You could create a custom class that will send the e-mail when a specific message is sent, specific source, etc.
I’m not sure if you could set it from the config with a custom class. You could programatically add the appender and set that property.
You may need to increase the BufferSize property in order to get the history of logs that you want.
Or you could roll your own appender. I can’t think of how you’d design it that would be much different than the SMTPAppender, though, except possibly making your buffer unlimited (which is a bit dangerous).
Alternately you could simply log to a rolling log file appender, and have a service/scheduled task start up every thirty minutes, e-mail off the log file, clean up, and die. I’ve done this on a production web app before, using scheduled tasks and batch files, deployed via an MSI we created in WIX, with a custom action to deploy the scheduled task.