log4net SMTP appender include previous log entries when a string match happens

158 Views Asked by At

I'm trying to design an SMTP appender configuration for log4net which will send an email with the previous log entries when a specific string match happens. The use case is we have a process which runs every day. I have an SMTPAppender which watches for errors and that works fine. But I want another SMTP appender which watches for the "Program success" message when the program finishes running and send an email to our ops guy with all the log entries for the run like this:

 1/1/2014 4:00 PM - Program started
 1/1/2014 4:01 PM - Program Running
 1/1/2014 4:02 PM - Program still running
 1/1/2014 4:03 PM - Program success

Here is sort of the template I've got going for an appender

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="[email protected]" />
  <from value="[email protected]" />
  <subject value="Program has run successfully" />
  <smtpHost value="mailserver.com" />
  <username value="" />
  <password value="" />
  <bufferSize value="512" />
  <lossy value="false" />
  <evaluator type="log4net.Core.???">
    What goes here?
  </evaluator>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
  </layout>
</appender>
1

There are 1 best solutions below

0
On BEST ANSWER

Creating your own implemetation of ITriggeringEventEvaluator would seem to be be the way to go. You can then get IsTriggeringEvent to return true when the passed LoggingEvent's RenderedMessage property contains the target string.