using log4net.Config; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; namespace ChangFa.Machinery.WebPage { public class MvcApplication : Spring.Web.Mvc.SpringMvcApplication { protected void Application_Start() { XmlConfigurator.Configure(); log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(Server.MapPath("~/App_Data/Config/log4net.config")));//记录日志路径配置 AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); } protected void Application_Error(object sender, EventArgs e) { try { //获取到HttpUnhandledException异常,这个异常包含一个实际出现的异常 Exception ex = Server.GetLastError(); //实际发生的异常 Exception iex = ex.InnerException; string errorMsg = String.Empty; string particular = String.Empty; if (iex != null) { errorMsg = iex.Message; particular = iex.StackTrace; } else { errorMsg = ex.Message; particular = ex.StackTrace; } //HttpContext.Current.Response.Write("来自Global的错误处理
"); //HttpContext.Current.Response.Write(errorMsg); //log4net.Ext.IExtLog log = log4net.Ext.ExtLogManager.GetLogger("Oraclelog"); //log.Info("系统异常", ex); //Server.ClearError();//处理完及时清理异常 } catch (Exception ee) { throw ee; } } } }