Raygun error and crash reporting for Episerver

Frederik Vig 22.05.2016 12.42.48

For us the main difference between Raygun and other error logging tools has been the maintenance aspect where it groups similar errors together, gives you details like the HTTP request data, browser environment and allows you to ignore, assign, mark as solved and also integrate with other tools we use like Octopus Deploy, GitHub and JIRA, and of course alerts to the right people. 

Installation

You can try out Raygun for free for 30 days. Go to https://app.raygun.com and register, add your application (if it's not already there). This will give you an API key to use.

Install the following package:

Install-Package Mindscape.Raygun4Net.Mvc

Configuration

Note: we only do this for production configurations.

Web.config

Add a section to configSections:

<section name="RaygunSettings" type="Mindscape.Raygun4Net.RaygunSettings, Mindscape.Raygun4Net"/>

Add the Raygun settings configuration block from above:

<RaygunSettings apikey="YOUR_APP_API_KEY" />

For system.web:

<httpModules>
<add name="RaygunErrorModule" type="Mindscape.Raygun4Net.RaygunHttpModule"/>
</httpModules>

For system.webServer:

<modules>
<add name="RaygunErrorModule" type="Mindscape.Raygun4Net.RaygunHttpModule"/>
</modules>

Log4Net

By default Raygun will catch all errors automatically from Application_Error. There's also a provider for Log4Net that you can use as an appender.

Here's an example configuration to append errors from Log4Net to Raygun. 

Install-Package log4net.Raygun

EPiserverLog.config

<?xml version="1.0" encoding="utf-8"?>
<log4net>
<appender name="errorFileLogAppender" type="log4net.Appender.RollingFileAppender" >
<!-- Consider moving the log files to a location outside the web application -->
<file value="..\appdata\SiteErrors.log" />
<encoding value="utf-8" />
<staticLogFileName value="true"/>
<datePattern value=".yyyyMMdd.'log'" />
<rollingStyle value="Date" />
<threshold value="Error" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger: %message%n" />
</layout>
</appender>
<appender name="outputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%thread] %level %logger: %message%n" />
</layout>
</appender>
<appender name="RaygunAppender" type="log4net.Raygun.RaygunAppender, log4net.Raygun">
<apiKey value="API-KEY" />
<retries value="15" />
<timeBetweenRetries value="00:01:00" />
<onlySendExceptions value="true" />
</appender>
<logger name="EPiServer.Core.OptimisticCache" additivity="false">
<level value="Error" />
</logger>
<logger name="EPiServer.Core.ContentProvider" additivity="false">
<level value="Error" />
</logger>
<logger name="EPiServer.Data.Dynamic.Providers.DbDataStoreProvider" additivity="false">
<level value="Error" />
</logger>
<logger name="EPiServer.Data.Providers.SqlDatabaseHandler" additivity="false">
<level value="Error" />
</logger>
<logger name="EPiServer.Data.Providers.ConnectionContext" additivity="false">
<level value="Error" />
</logger>
<root>
<level value="Error" />
<appender-ref ref="RaygunAppender" >
<threshold value="Error" />
</appender-ref>
</root>
</log4net>