How to set up Elmah with ASP.NET Web API

前端 未结 4 2073
忘了有多久
忘了有多久 2021-01-31 08:18

I\'ve tried many elmah nugets but they didn\'t work with ASP.NET Web API. Does anybody knows why? Is there any work around for that?

4条回答
  •  佛祖请我去吃肉
    2021-01-31 08:56

    Check the below URL it describe in details how to use elmah with Web API:

    http://blogs.msdn.com/b/webdev/archive/2012/11/16/capturing-unhandled-exceptions-in-asp-net-web-api-s-with-elmah.aspx

    You can also use the NuGet Package below:

    Install-Package Elmah.Contrib.WebApi
    

    Usage:

    Simply register it during your application's start up, or on a controller-by-controller basis.

    protected void Application_Start()
    {
        GlobalConfiguration.Configuration.Filters.Add(new ElmahHandleErrorApiAttribute());
    
        ...
    }
    

    (from the Elmah.Contrib.WebApi GitHub repo)

提交回复
热议问题