내 MVC 웹 프로젝트에서. web.config에서 "custromerrors"요소를 사용하지 않고 방문자에게 사용자 정의 오류 페이지를 표시하려고합니다.예외를 로깅하지 않는 Elmah
내가 ELMAH 캔트 로그 오류는 내가 오류 신호를 제기하고
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
bool success = RaiseErrorSignal(exception);
Response.Clear();
HttpException httpException = exception as HttpException;
RouteData routeData = new RouteData();
routeData.Values.Add("controller", "Error");
if (httpException == null)
{
routeData.Values.Add("action", "Index");
}
else //It's an Http Exception, Let's handle it.
{
switch (httpException.GetHttpCode())
{
case 404:
// Page not found.
routeData.Values.Add("action", "Error404");
break;
case 500:
// Server error.
routeData.Values.Add("action", "Error500");
break;
// Here you can handle Views to other error codes.
// I choose a General error template
default:
routeData.Values.Add("action", "Index");
break;
}
}
// Pass exception details to the target error View.
routeData.Values.Add("error", exception);
// Clear the error on server.
Server.ClearError();
// Call target Controller and pass the routeData.
IController errorController = new ProjectName.WebSite.Controllers.ErrorController();
errorController.Execute(new RequestContext(
new HttpContextWrapper(Context), routeData));
}
private static bool RaiseErrorSignal(Exception e)
{
var context = HttpContext.Current;
if (context == null)
return false;
var signal = ErrorSignal.FromContext(context);
if (signal == null)
return false;
signal.Raise(e, context);
return true;
}
이하 그러나 같은 예외를 잡을 수 있습니다.
귀하의 질문은 무엇입니까? 내가 보는 모든 결론입니다. –
signal.Raise (e, context)가 작동하지 않습니다. 예외를보기 위해 /elmah.axd에 갈 때 목록이 비어 있기 때문입니다. – Yucel