I am trying to add error-tracking service Raygun to Orchard, however I am not sure how to intercept exception thrown by the application.
In the default ASP.NET MVC it is usually done through Application_Error()
in Global.asax.cs
, is there a way to similarly do it in Orchard CMS?
The only way I found it to do is to explicitly put the code into the custom ErrorPage.cshtml
.
The recommended way is to provide a custom implementation of the Orchard.Exceptions.IExceptionPolicy
interface. In your scenario, you can use the default implementation DefaultExceptionPolicy
as a fallback.
For example you can implement the following class in your custom Orchard module.
[OrchardSuppressDependency("Orchard.Exceptions.DefaultExceptionPolicy")]
public class IssueTrackerExceptionPolicy : DefaultExceptionPolicy, IExceptionPolicy
{
bool IExceptionPolicy.HandleException(object sender, Exception exception)
{
// TODO: Log exception here.
return base.HandleException(sender, exception);
}
}