How to get ELMAH to work with ASP.NET MVC [HandleError] attribute?

前端 未结 8 2076
后悔当初
后悔当初 2020-11-22 02:53

I am trying to use ELMAH to log errors in my ASP.NET MVC application, however when I use the [HandleError] attribute on my controllers ELMAH doesn\'t log any errors when the

8条回答
  •  执笔经年
    2020-11-22 03:19

    I'm new in ASP.NET MVC. I faced the same problem, the following is my workable in my Erorr.vbhtml (it work if you only need to log the error using Elmah log)

    @ModelType System.Web.Mvc.HandleErrorInfo
    
        @Code
            ViewData("Title") = "Error"
            Dim item As HandleErrorInfo = CType(Model, HandleErrorInfo)
            //To log error with Elmah
            Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(New Elmah.Error(Model.Exception, HttpContext.Current))
        End Code
    
    

    Sorry, an error occurred while processing your request.
    @item.ActionName
    @item.ControllerName
    @item.Exception.Message

    It is simply!

提交回复
热议问题