我如何记录未处理的ASP.NET MVC异常? [英] How do I log unhandled exceptions in ASP.NET MVC?

查看:220
本文介绍了我如何记录未处理的ASP.NET MVC异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面就是我想要做我的Global.asax.vb:

Here's what I'm trying to do in my Global.asax.vb:

Public Class MvcApplication
    Inherits System.Web.HttpApplication

    Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
        routes.MapRoute( _
            "Error", _
            "error.html", _
            New With {.controller = "Error", _
                      .action = "FriendlyError"} _
        )
        ...
        'other routes go here'
        ...
    End Sub

    Sub Application_Start()
        RegisterRoutes(RouteTable.Routes)
    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ...
        'code here logs the unhandled exception and sends an email alert'
        ...
        Server.Transfer("http://www.example.com/error.html")
    End Sub

End Class

但是,Server.Transfer的失败:

But that Server.Transfer fails:

无效的路径子请求 http://www.example.com/ 的error.html。虚拟路径的预期。

Invalid path for child request 'http://www.example.com/error.html'. A virtual path is expected.

我该如何解决这个问题?或者,有什么更好的方法为我做到这一点?

How do I fix this? Or, what's a better way for me to do this?

推荐答案

我刚刚发现这对斯科特Hanselman的博客<一href="http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx">here所谓 ELMAH 这是一个错误记录器/处理器,您可以使用,而无需改变你的code。你可能想看看它,因为它似乎与MVC很好地工作。

I just found this on Scott Hanselman's blog here called ELMAH which is an Error Logger/Handler that you can use without having to change your code. You might want to look into it, since it seems to work nicely with MVC.

这篇关于我如何记录未处理的ASP.NET MVC异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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