0

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.

Michel
  • 51
  • 5

1 Answers1

1

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);
    }
}
Marek Dzikiewicz
  • 2,844
  • 1
  • 22
  • 24
  • Although it's questionable whether you should do that at all, as there already is Log4Net support out of the box, which should suffice for most scenarios. It would be interesting to know what the specific scenario is here. – Bertrand Le Roy Jun 10 '15 at 06:22
  • Well logging is not always good enough. I use a very simliar solution to automatically report unhandled exceptions from Orchard applications to a bugtracking system (YouTrack in my case). It works very well. – Marek Dzikiewicz Jun 10 '15 at 09:10
  • Thanks for the reply. That's exactly what I need. Bertrand, yes, I need to report errors to another but tracking system. – Michel Jun 10 '15 at 19:35