Use log4net filter to dispatch email notification based on string match

  • filter type set to log4net.Filter.StringMatchFilter
  • each filter section can only have one stringToMatch element
  • end with a “log4net.Filter.DenyAllFilter” filter to switch from the default “accept all unless instructed otherwise” filtering behavior to a “deny all unless instructed otherwise” behavior.
<?xml version="1.0" encoding="utf-8"?>
<log4net debug="false">

  <appender name="SmtpAppender_WebTeam" type="log4net.Appender.SmtpAppender">
    <to value="goodguy@me.com" />
    <from value="log4net@me.ca" />
    <subject value="!!!Web Exception happened!!!" />
    <smtpHost value="mail.server.ds" />
    <bufferSize value="512" />
    <lossy value="true" />
    <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="ERROR"/>
    </evaluator>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
    </layout>
 	<filter type="log4net.Filter.StringMatchFilter">
		<stringToMatch value="RequestManagement" />
 	</filter>
 	<filter type="log4net.Filter.StringMatchFilter">
		<stringToMatch value="VineOnLine" />
 	</filter>
	<filter type="log4net.Filter.DenyAllFilter" />
  </appender>
  <appender name="SmtpAppender_VSE" type="log4net.Appender.SmtpAppender">
    <to value="nice@me.ca" />
    <from value="log4net@mr.ca" />
    <subject value="!!!VSE Exception happened!!!" />
    <smtpHost value="mail.server.ds" />
    <bufferSize value="512" />
    <lossy value="true" />
    <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="ERROR"/>
    </evaluator>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
    </layout>
	<filter type="log4net.Filter.StringMatchFilter">
		<stringToMatch value="VSE" />
	</filter>
    <filter type="log4net.Filter.DenyAllFilter" />
  </appender>

  <root>
    <level value="INFO" />

    <appender-ref ref="SmtpAppender_WebTeam" />
    <appender-ref ref="SmtpAppender_VSE" />

  </root>
  <logger name="NHibernate">
    <level value="ERROR"/>
  </logger>

</log4net>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s