错误使用ELMAH用的WebAPI登录时两次 [英] Errors are logged twice when using Elmah with WebApi

查看:225
本文介绍了错误使用ELMAH用的WebAPI登录时两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图登录使用ELMAH我的asp.net的web API项目例外。我有其中记录两次,每次错误的问题。

I'm trying to log exceptions from my asp.net web api project using elmah. I am having an issue where each error is logged twice.

如下:

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        GlobalConfiguration.Configuration.Filters.Add(new ElmahHandleErrorApiAttribute());

        RouteTable.Routes.MapHubs();
        RouteConfig.RegisterRoutes(RouteTable.Routes);

#if DEBUG
        EntityFrameworkProfiler.Initialize();
#endif

        GlobalConfig.CustomizeConfig(GlobalConfiguration.Configuration);

    }
}

如果我commment出以下行,然后我在所有得到任何消息:

If I commment out the following line then I get no messages at all:

GlobalConfiguration.Configuration.Filters.Add(new ElmahHandleErrorApiAttribute());

和我可以证实,我只扔一次错误而产生的错误只被调用一次,我没有手工装饰了我的控制器或方法与ELMAH属性电话。

And I can confirm that I am only throwing one error and the call which generates the error is only been called once and I've not manually decorated my controllers or methods with the Elmah Attribute.

要尝试解决这个我去掉了包装的Contrib添加和这里遵循中的说明<一个href=\"http://www.tugberkugurlu.com/archive/asp-net-web-api-and-elmah-integration\">http://www.tugberkugurlu.com/archive/asp-net-web-api-and-elmah-integration

To try and resolve this I removed The Contrib Package and added followed the instructions found here http://www.tugberkugurlu.com/archive/asp-net-web-api-and-elmah-integration

这并没有解决问题,它仍然记录了两次。这确实让我把一个破发点到属性类,并确认每一个错误它被调用两次。

This did not solve the issue and it still logs twice. It did allow me to put a break point into the Attribute class and confirm that for each error it is being called twice.

我该如何解决呢?

推荐答案

有关它的价值,我有我的Web API应用记录每个异常的两倍(使用Elmah.Contrib.WebApi)ELMAH同样的问题。

For what it's worth, I was having the same problem of ELMAH logging each exception twice in my Web API application (using Elmah.Contrib.WebApi).

我比较ELMAH电子邮件对我的源代码历史,我能够确定的Ninject.Web.WebApi 3.0.2不稳定-9016封装是通过安装的NuGet后问题开始发生。

Comparing my ELMAH emails against my source history, I was able to identify that the problem started happening after the Ninject.Web.WebApi 3.0.2-unstable-9016 package was installed via nuget.

果然,卸载包并注释掉单一依赖绑定使用它解决了双异常记录的问题。重新安装包和离开的依赖绑定注释掉导致该问题再次启动,所以它不是绑定本身。

Sure enough, uninstalling the package and commenting out the single dependency binding that was using it solved the double exception logging problem. Reinstalling the package and leaving the dependency binding commented out caused the problem to start again, so it wasn't the binding itself.

安装previous版本(3.0.2 Ninject.Web.WebApi不稳定-8)并没有引起发生的问题,但我的依赖绑定不再奏效。

Installing the previous version (Ninject.Web.WebApi 3.0.2-unstable-8) did not cause the problem to happen, but my dependency binding no longer worked.

我选择住暂时的问题。

这篇关于错误使用ELMAH用的WebAPI登录时两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆