Search code examples
asp.net-web-apielmah.mvc

Elmah exception handling with OnException Filter WebAPI


If I implement an exception filter in a WEB API project, and I throw an exception in a controller will elmah log the thrown exception even though I have an exception filter?If so how can I force elmah not to log that exception?


Solution

  • ELMAH itself won't log the exception at all, since Web API isn't supported out of the box. You need some additional code to log exceptions from Web API, but luckily someone already did the hard work:

    https://github.com/rdingwall/elmah-contrib-webapi

    When Elmah.Contrib.WebApi is hooked up, ELMAH will log your exceptions, even though you modify your response or something else in an exception filter.