Skip to content

Instantly share code, notes, and snippets.

@markberryman
Created November 17, 2012 01:42
Show Gist options
  • Save markberryman/4092536 to your computer and use it in GitHub Desktop.
Save markberryman/4092536 to your computer and use it in GitHub Desktop.
Web API UnhandledExceptionFilter Example
public class UnhandledExceptionFilter : ExceptionFilterAttribute {
public override void OnException(HttpActionExecutedContext context) {
Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(context.Exception));
}
}
public static class WebApiConfig {
public static void Register(HttpConfiguration config) {
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Filters.Add(new UnhandledExceptionFilter());
}
}
@chuchuva
Copy link

More concise:

Elmah.ErrorSignal.FromCurrentContext().Raise(context.Exception);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment