Global.asax.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using log4net.Config;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Http;
  7. using System.Web.Mvc;
  8. using System.Web.Optimization;
  9. using System.Web.Routing;
  10. namespace ChangFa.Machinery.WebPage
  11. {
  12. public class MvcApplication : Spring.Web.Mvc.SpringMvcApplication
  13. {
  14. protected void Application_Start()
  15. {
  16. XmlConfigurator.Configure();
  17. log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(Server.MapPath("~/App_Data/Config/log4net.config")));//记录日志路径配置
  18. AreaRegistration.RegisterAllAreas();
  19. GlobalConfiguration.Configure(WebApiConfig.Register);
  20. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  21. RouteConfig.RegisterRoutes(RouteTable.Routes);
  22. BundleConfig.RegisterBundles(BundleTable.Bundles);
  23. }
  24. protected void Application_Error(object sender, EventArgs e)
  25. {
  26. try
  27. {
  28. //获取到HttpUnhandledException异常,这个异常包含一个实际出现的异常
  29. Exception ex = Server.GetLastError();
  30. //实际发生的异常
  31. Exception iex = ex.InnerException;
  32. string errorMsg = String.Empty;
  33. string particular = String.Empty;
  34. if (iex != null)
  35. {
  36. errorMsg = iex.Message;
  37. particular = iex.StackTrace;
  38. }
  39. else
  40. {
  41. errorMsg = ex.Message;
  42. particular = ex.StackTrace;
  43. }
  44. //HttpContext.Current.Response.Write("来自Global的错误处理<br />");
  45. //HttpContext.Current.Response.Write(errorMsg);
  46. //log4net.Ext.IExtLog log = log4net.Ext.ExtLogManager.GetLogger("Oraclelog");
  47. //log.Info("系统异常", ex);
  48. //Server.ClearError();//处理完及时清理异常
  49. }
  50. catch (Exception ee) { throw ee; }
  51. }
  52. }
  53. }