Post

Log4Net email logging

Configuring Log4Net to send email alerts when errors occur in a specific class — useful for Umbraco and other .NET applications.

Log4Net is a powerful logging framework used by Umbraco. Beyond basic file logging, it can be configured to send email notifications when errors occur — invaluable for catching production issues early.

Add the following configuration to the xml > log4net section of /Config/log4net.config:

<root>
  <priority value="Error"/>
  <appender-ref ref="APPENDER_NAME" />
</root>  

<appender name="APPENDER_NAME" type="log4net.Appender.SmtpAppender">
  <to value="EMAIL_TO" />
  <from value="EMAIL_FROM" />
  <subject value="EMAIL_SUBJECT" />
  
  <smtpHost value="SMTP_HOST_NAME" />
  <port value="SMTP_PORT" />
  <authentication value="Basic"/>
  <userName value="SMTP_USERNAME" />
  <password value="SMTP_PASSWORD" />
  <enableSsl value="SMTP_ENABLE_SSL" />
  
  <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.LoggerMatchFilter">
    <loggerToMatch value="LOGGER_TO_MATCH" />
  </filter>
  <filter type="log4net.Filter.DenyAllFilter" />
</appender>

Configuration Parameters

PlaceholderDescriptionExample
APPENDER_NAMEUnique identifier for this appenderMySmtpAppender
EMAIL_TORecipient email addressalerts@example.com
EMAIL_FROMSender addressno-reply@example.com
EMAIL_SUBJECTEmail subject lineApplication Error
SMTP_HOST_NAMESMTP server hostnameemail-smtp.eu-west-1.amazonaws.com
SMTP_PORTSMTP port25, 465, or 587
SMTP_USERNAMESMTP authentication username
SMTP_PASSWORDSMTP authentication password
SMTP_ENABLE_SSLEnable SSL/TLStrue or false
LOGGER_TO_MATCHFully qualified class name to filter onMy.Namespace.MyClass

The DenyAllFilter at the end ensures only log events from the matched class trigger emails — without it, all ERROR level events in the application would be sent.

← Back to all posts