我的程序日志记录代码如下:
protected override void OnException(ExceptionContext filterContext)
{
log4net.Error("【IP】" + filterContext.HttpContext.Request.UserHostAddress + "\r\n\r\n" +
"【Url】" + filterContext.HttpContext.Request.Url.AbsoluteUri + "\r\n\r\n" +
"【Message】" + filterContext.Exception.Message + "\r\n\r\n" +
"【StackTrace】" + filterContext.Exception.StackTrace + "\r\n\r\n");
}
得到的日志信息如下:
【Message】Object reference not set to an instance of an object.
【StackTrace】 at ASP._Page_Views_List_test_cshtml.Execute()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
这是一个很常见的“Object reference not set to an instance of an object”错误,IP跟URL没帖出来,通过这个日志我仅能知道是哪个页面出错了,但不能精确地知道错误的出错位置,请问有没有办法可以精确地定位。
森林海
ABOUTYOU
倚天杖
交互式爱情
千万里不及你
慕妹3242003
天涯尽头无女友