2

A requirement in one of the projects is to get email alerts for logs in production and UAT environment. Whenever an error occurs and is logged, an email alert is to be sent to pre-defined recipients. This should include logs for handled as well as unhandled exceptions. Moreover, in future, if client wants to get email alerts for WARN or INFO logs as well, then it should be configurable.

We analyzed Elmah, but it only works for unhandled exceptions. Can anybody please suggest if they have come across any tool/ module to achieve this functionality if they had any similar requirement?

Note - The project is on Sitecore 9.2.

1
  • 1
    Ship all the logs to loggly and use loggly to send alerts when it sees the error you are looking for.
    – Chris Auer
    Commented Jun 23, 2020 at 13:30

1 Answer 1

3

For logs monitoring, analysis and alerting, I would recommend to look for a tool like Sumo Logic that offers the ability to create scheduled searches and send notifications (via emails, webhooks,...) when a specific condition is met. Sumo Logic is able to collect and monitor application logs (like your Sitecore logs), where your handled exceptions are tracked, but also Windows Event logs where your unhandled exceptions are tracked.

If you don't want to use an external tool, you can add and configure a custom log4net SmtpAppender to your Sitecore solution. This appender would give you the ability to send log records to an email recipient and to filter them based on log levels (min and max). This is an example of the configuration needed to configure an SmtpAppender in a Sitecore solution:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore> 
    <log4net>
      <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender, Sitecore.Logging" patch:after="*[@ref='LogFileAppender']">
        <to value="[email protected]" />
        <from value="[email protected]" />
        <subject value="Email Subject" />
        <smtpHost value="mail.example.com" />
        <bufferSize value="1" />
        <lossy value="false" />
        <filter type="log4net.Filter.LevelRangeFilter">
          <levelMin value="ERROR" />
          <levelMax value="FATAL" />
        </filter>
        <layout type="log4net.Layout.PatternLayout">
          <conversionpattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
        </layout>
      </appender>
      <root>
       <appender-ref ref="SmtpAppender" patch:after="*[@ref='LogFileAppender']" />
      </root>
    </log4net>
  </sitecore>
</configuration>

If you want to catch all the exceptions (handled and unhandled) in your web application, you should catch them adding global error handling in your global.asax file in the Application_Error method.

1
  • With log4net.Appender.SmtpAppender, you need an SMTP host that can work with no authentication. Commented Jun 23, 2020 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.