title: Use Elmah to Catch Unhandled Exceptions using IExceptionFilter
body: <p>I'm trying to convert some code I found for MVC to work in regular Asp.Net. In short I want to be able to log handled exceptions using Elmah, without having to call a logging method every time the exception occurs. I've looked all around for this and all the solutions I find use MVC. I found a simple and elegant one here and even though my application uses MVC for client side calls, it's not a full blown MVC project so I guess it's not going to work or I'm missing something.</p>
  
  <p>So here is the code</p>
  
  <pre><code>public class ElmahHandledErrorLoggerFilter : IExceptionFilter
  {
      public void OnException (ExceptionContext context)
      {
          // Log only handled exceptions, because all other will be caught by ELMAH anyway.
          if (context.ExceptionHandled)
              ErrorSignal.FromCurrentContext().Raise(context.Exception);
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public static void RegisterGlobalFilters (GlobalFilterCollection filters)
  {
      filters.Add(new ElmahHandledErrorLoggerFilter());
      filters.Add(new HandleErrorAttribute());
  }
  </code></pre>
  
  <p>The post from:
  <a href="https://stackoverflow.com/questions/766610/how-to-get-elmah-to-work-with-asp-net-mvc-handleerror-attribute/5936867#5936867">How to get ELMAH to work with ASP.NET MVC [HandleError] attribute?</a></p>
  
  <p>Says to place the second code block in the global.asax file. The event never gets called for me so I'm wondering if I have to call it myself and if I do then what am I passing to it? I'd prefer to know what the equivalent for regular asp net would be as I'm not familiar with MVC although since i have a reference to the MVC dll I would be open to trying to get it to work 'as is' if someone has ideas. </p>