This is part 2 of 3 of the article started here.
Carrying on from the previous example, I’d like to have a look at the appenders. There are numerous appenders that come standard with log4net, ranging from the FileAppender and RollingFileAppender (logging to files) to the EventLogAppender and SMTPAppender. You can have a look in the log4net.Appender namespace to see what else is available.
Below is an appender section that is set up for logging to the event log:
<appender name="EventLog" type="log4net.Appender.EventLogAppender">
<applicationName value="Logging Application" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="Application id:002%newlineVersion:release 2.0%newlineType:NT Service%newlineEnvironment:LIVE%newlineProcess id:%property{processId}%newlineComponent:%a - %C%newlineMethod:%M%newlineMessage:%m%newlineException:%exception"/>
</layout>
</appender>
And here is another for using SMTP logging:
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="youremail@something.com" />
<from value="youremail@something.com" />
<subject value="Application Error" />
<smtpHost value="yourhost" />
<bufferSize value="512" />
<lossy value="true" />
<threshold value="ERROR"/>
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="DEBUG"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger - %message%newline%newline%newline" />
</layout>
</appender>
Remember to add an entry in the <root> to make sure that your new appenders are going to be used.
In the next article, I'll discuss using the different logger types.
Part 3 of this article.