You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 line
2.8 KiB

  1. using Glorysoft.SECS.EQP.Utilities;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. namespace ARI.EAP.HOST
  9. {
  10. static class Program
  11. {
  12. /// <summary>
  13. /// 应用程序的主入口点。
  14. /// </summary>
  15. [STAThread]
  16. static void Main()
  17. {
  18. try
  19. {
  20. //设置应用程序处理异常方式:ThreadException处理
  21. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
  22. //处理UI线程异常
  23. Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
  24. //处理非UI线程异常
  25. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  26. Application.EnableVisualStyles();
  27. Application.SetCompatibleTextRenderingDefault(false);
  28. Application.Run(new MainForm());
  29. }
  30. catch (Exception ex)
  31. {
  32. string str = GetExceptionMsg(ex, string.Empty);
  33. LoggerService.SYSLogger.Error(str);
  34. }
  35. }
  36. static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
  37. {
  38. string str = GetExceptionMsg(e.Exception, e.ToString());
  39. LoggerService.SYSLogger.Error(str);
  40. }
  41. static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  42. {
  43. string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());
  44. LoggerService.SYSLogger.Error(str);
  45. }
  46. /// <summary>
  47. /// 生成自定义异常消息
  48. /// </summary>
  49. /// <param name="ex">异常对象</param>
  50. /// <param name="backStr">备用异常消息:当ex为null时有效</param>
  51. /// <returns>异常字符串文本</returns>
  52. static string GetExceptionMsg(Exception ex, string backStr)
  53. {
  54. StringBuilder sb = new StringBuilder();
  55. sb.AppendLine("****************************异常文本****************************");
  56. sb.AppendLine("【出现时间】:" + DateTime.Now.ToString());
  57. if (ex != null)
  58. {
  59. sb.AppendLine("【异常类型】:" + ex.GetType().Name);
  60. sb.AppendLine("【异常信息】:" + ex.Message);
  61. sb.AppendLine("【堆栈调用】:" + ex.StackTrace);
  62. }
  63. else
  64. {
  65. sb.AppendLine("【未处理异常】:" + backStr);
  66. }
  67. sb.AppendLine("***************************************************************");
  68. return sb.ToString();
  69. }
  70. }
  71. }