【问题标题】:Sentry is not logging 404 errors for ASP.NET MVC siteSentry 没有为 ASP.NET MVC 站点记录 404 错误
【发布时间】:2017-10-28 04:42:23
【问题描述】:

我已成功连接 SharpRaven 以从 MVC 和 Web API 控制器成功记录和捕获错误,但无法记录和捕获 404 错误。

我正在尝试通过Application_Error 这样做:

public class MvcApplication : System.Web.HttpApplication
{
    RavenClient _RavenClient;

    protected void Application_Start()
    {
        _RavenClient = new RavenClient(ConfigurationManager.AppSettings["RavenClient:DNS"]);

        ...
    }

    protected void Application_Error(object sender, EventArgs e)
    {
        _RavenClient.Capture(new SentryEvent(Server.GetLastError()));
    }
}

如果我在 _RavenClient.Capture(...) 上设置断点,我可以看到错误被捕获,但此处捕获的 404 错误永远不会出现在 https://sentry.io/

如果我禁用其他控制器集成,这也适用于命中这行代码的非 404 异常。

任何想法为什么这不能完全工作?有没有更好的方法可以让我有更好的工作机会?

【问题讨论】:

    标签: c# asp.net-mvc error-logging sentry


    【解决方案1】:

    如果我在 Application_Error 方法本身中需要它时创建 RavenClient,一切都会按预期工作。看来在Application_Start创建客户端,以后再使用肯定有问题。

    这是我修改后的工作代码:

    protected void Application_Error(object sender, EventArgs e)
    {
        new RavenClient(ConfigurationManager.AppSettings["RavenClient:DNS"])
            .Capture(new SentryEvent(Server.GetLastError()));
    }
    

    【讨论】:

      猜你喜欢
      • 2014-05-20
      • 1970-01-01
      • 2010-10-08
      • 2014-01-04
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 2012-12-08
      • 2011-08-10
      相关资源
      最近更新 更多