using System; using System.Web; using Abp.Castle.Logging.Log4Net; using Abp.Dependency; using Abp.Timing; using Abp.Web; using Abp.Web.Localization; using Castle.Facilities.Logging; using WePlatform.Configuration; using IwbZero.ToolCommon.LogHelpers; using WePlatform.CommonManager.AppGuids; namespace WePlatform { public class MvcApplication : AbpWebApplication { protected override void Application_Start(object sender, EventArgs e) { AbpBootstrapper.IocManager.IocContainer.AddFacility( f => f.UseAbpLog4Net().WithConfig(Server.MapPath("log4net.config")) ); this.LogInfo("Application -- System Starting!"); base.Application_Start(sender, e); //加载RECORDID文件 RecordIdManager.LoadDictionary(); this.LogInfo("Application -- System Started!"); } protected override void Application_End(object sender, EventArgs e) { // 在应用程序关闭时运行的代码 this.LogInfo("Application -- System End!"); } protected override void Application_Error(object sender, EventArgs e) { // 在出现未处理的错误时运行的代码 //获取到HttpUnhandledException异常,这个异常包含一个实际出现的异常 Exception ex = Server.GetLastError(); //实际发生的异常 Exception innerException = ex.InnerException; if (innerException != null) ex = innerException; this.LogFatal(ex); } protected override void Application_BeginRequest(object sender, EventArgs e) { var langCookie = Request.Cookies[IwbConsts.LocalizationCookieName]; if (langCookie == null) { Context.Response.SetCookie( new HttpCookie(IwbConsts.LocalizationCookieName, "zh-Hans") { Expires = Clock.Now.AddYears(2), Path = Context.Request.ApplicationPath } ); } base.Application_BeginRequest(sender, e); } protected override void Session_Start(object sender, EventArgs e) { // 在新会话启动时运行的代码 this.LogInfo("Session_Start"); } protected override void Session_End(object sender, EventArgs e) { // 在会话结束时运行的代码。 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 InProc 时,才会引发 Session_End 事件。 // 如果会话模式设置为 StateServer // 或 SQLServer,则不会引发该事件。 this.LogInfo("Session_End"); } protected override void SetCurrentCulture() { AbpBootstrapper.IocManager.Using(cultureSetter => cultureSetter.SetCurrentCulture(Context)); } } }