我已经在web.config中处理了错误500和404
<httpErrors errorMode="Custom" existingResponse="Replace"> --><!--defaultPath="/Errors/NotFound"--><!--
<remove statusCode="404" subStatusCode="-1"/>
<remove statusCode="500" subStatusCode="-1"/>
<error statusCode="404" path="/Errors/NotFound" responseMode="ExecuteURL"/>
<error statusCode="500" path="/Errors/ServerError" responseMode="ExecuteURL"/>
</httpErrors> 但问题是,目前我不能在事件查看器中看到500和404个错误以及它们对应的堆栈跟踪
我在Application_Error上使用了微软应用程序洞察的错误处理,但它不像事件查看器那样具有描述性
protected void Application_Error(object sender, EventArgs e)
{
var exception = Server.GetLastError();
var httpStatusCode = (int)HttpStatusCode.InternalServerError;
try
{
httpStatusCode = ((HttpException) exception).GetHttpCode();
}
catch (Exception)
{
}
var dateTime = DateTime.Now.ToString();
var ip = Request.ServerVariables["REMOTE_ADDR"];
var userName = string.Empty;
try
{
userName = HttpContext.Current.User.Identity.Name;
}
catch
{
}
var url = string.Empty;
if (HttpContext.Current != null)
{
url = HttpContext.Current.Request.Url.ToString();
}
var log = string.Format("Url: {0} , httpStatusCode: {1}, " +
"dateTime: {2}, exceptionMessage: {3}, " +
"ipAddress: {4}, userName: {5} ",
url, httpStatusCode, dateTime, exception.Message, ip, userName);
ServerAnalytics.CurrentRequest.LogEvent(log);
}我需要有清晰的错误日志,如事件查看器
我该怎么办?
还有其他选择吗?新的遗物,应用程序洞察?
发布于 2014-08-16 20:41:55
您没有在日志记录中使用异常堆栈跟踪。在错误日志中不使用exception.message,而是使用exception.ToString(),它将包含堆栈跟踪。
https://stackoverflow.com/questions/25339801
复制相似问题