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.