kai*_*lya 29 c# asp.net asp.net-mvc logging log4net
你能指点我一些关于如何使用log4net记录我的mvc web应用程序上发生的未处理异常的教程或示例.谢谢
kai*_*lya 52
我粘贴在我的global.asax上使用的代码下面,这似乎现在让我满意..我在log4net生成的日志文件中得到所有未处理的异常..
public class MvcApplication : System.Web.HttpApplication
{
private static readonly ILog log = LogManager.GetLogger(typeof(MvcApplication));
void Application_Error(Object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
log.Error("App_Error", ex);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
log4net.Config.XmlConfigurator.Configure();
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
对于ASP.NET应用程序,您喜欢使用System.Web.HttpApplication.Error
放在Global.asax
文件中的事件.
protected void Application_Error(Object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
// Stop error from displaying on the client browser
Context.ClearError();
logger.Fatal(ex.ToString);
}
Run Code Online (Sandbox Code Playgroud)
watch 管理未处理的异常
归档时间: |
|
查看次数: |
26394 次 |
最近记录: |