你能给我推荐一些教程或示例,告诉我如何使用log4net记录我的MVC web应用程序上发生的所有un-handled exceptions个事件吗?谢谢
你能给我推荐一些教程或示例,告诉我如何使用log4net记录我的MVC web应用程序上发生的所有un-handled exceptions个事件吗?谢谢
我将我在global.asax上使用的代码粘贴在下面,目前似乎满足了我的要求.我在log4net生成的日志(log)文件中收到所有未处理的异常.
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();
}
}