log4net smtp logging

In umbraco v6 logging is now performed by the excellent log4net library.  In the umbraco config directory you have the log4net.config file which is where everything is setup.  The really cool thing about log4net is you can have appenders of different types e.g file, database and smtp. You can also create your own which is what I did when I wrote LiveLogger.

So I am currently working on a project and I need to do some smtp logging of errors. Something has gone very wrong and I need to know about it as its mission critical. So I added an smtp appender to the config

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="jo@site.com" />
<from value="me@site.com" />
<subject value="Info graphic error" />
<smtpHost value="localhost" />
<bufferSize value="512" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ERROR"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />

This works however I get too much noise. There are other errors being generated that I am not interested in. So what you can do with log4net is to an appender add a filter so you can tell it you are only interested in certain classes only

<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="MyProject.BusinessLogic.Helpers.RazorHelper" />
<filter type="log4net.Filter.DenyAllFilter" />

So now I will only get emails for errors that occur in class RazorHelper. In this class I have logging statements that look like

LogHelper.Error(typeof(RazorHelper), "Error writing to eloqua for email address " + record.EmailAddress, webex);