Program.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using DevExpress.LookAndFeel;
  2. using DevExpress.XtraEditors;
  3. using Serilog;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Configuration;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace CG
  15. {
  16. internal static class Program
  17. {
  18. static Program()
  19. {
  20. AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "AddIns;");
  21. var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);
  22. var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
  23. m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", "AddIns;" });
  24. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  25. {
  26. var args = e.ExceptionObject as Exception;
  27. XtraMessageBox.Show("出现未处理的异常,程序即将退出!");
  28. Serilog.Log.Error("出现未处理的异常,程序即将退出!", args);
  29. };
  30. Application.ThreadException += (sender, e) =>
  31. {
  32. XtraMessageBox.Show(e.Exception.Message);
  33. Serilog.Log.Error("未处理的线程异常", e.Exception);
  34. };
  35. }
  36. /// <summary>
  37. /// 应用程序的主入口点。
  38. /// </summary>
  39. [STAThread]
  40. static void Main()
  41. {
  42. Serilog.Log.Logger = new Serilog.LoggerConfiguration()
  43. .WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
  44. .WriteTo.Logger(p => p.Filter.ByIncludingOnly(e => e.Level == Serilog.Events.LogEventLevel.Information)
  45. .WriteTo.File("Logs\\Info\\.log", rollingInterval: Serilog.RollingInterval.Day))
  46. .WriteTo.Logger(p => p.Filter.ByIncludingOnly(e => e.Level == Serilog.Events.LogEventLevel.Warning)
  47. .WriteTo.File("Logs\\Warning\\.log", rollingInterval: Serilog.RollingInterval.Day))
  48. .WriteTo.Logger(p => p.Filter.ByIncludingOnly(e => e.Level == Serilog.Events.LogEventLevel.Error)
  49. .WriteTo.File("Logs\\Error\\.log", rollingInterval: Serilog.RollingInterval.Day))
  50. .CreateLogger();
  51. WindowsFormsSettings.AllowDpiScale = true;
  52. WindowsFormsSettings.AllowHoverAnimation = DevExpress.Utils.DefaultBoolean.True;
  53. WindowsFormsSettings.AllowDefaultSvgImages = DevExpress.Utils.DefaultBoolean.True;
  54. WindowsFormsSettings.AllowRoundedWindowCorners = DevExpress.Utils.DefaultBoolean.True;
  55. WindowsFormsSettings.AnimationMode = AnimationMode.EnableAll;
  56. WindowsFormsSettings.BackgroundSkinningMode = BackgroundSkinningMode.AllColors;
  57. WindowsFormsSettings.DefaultAllowHtmlDraw = true;
  58. WindowsFormsSettings.DefaultLookAndFeel.SetSkinStyle(SkinStyle.WXICompact);
  59. WindowsFormsSettings.DefaultFont = new System.Drawing.Font("微软雅黑", 10f);
  60. WindowsFormsSettings.SetPerMonitorDpiAware();
  61. if (Debugger.IsAttached)
  62. {
  63. //DevExpress23.2以上版本查看未本地化的资源
  64. //DevExpress.Utils.Localization.XtraLocalizer.EnableTraceSource();
  65. }
  66. string screenTitle = ConfigurationManager.AppSettings["SystemName"];
  67. string screenCompany = ConfigurationManager.AppSettings["Company"];
  68. DxHelper.WaitHelper.SetSplashTips("Tips.txt");
  69. ChsLocalizer.UseChs();
  70. DxHelper.WaitHelper.ShowSplashScreen(screenTitle, screenCompany);
  71. DxHelper.WaitHelper.UpdateSplashMessage("正在加载程序资源文件...");
  72. MainForm mainForm = new MainForm() { Text = screenTitle };
  73. Thread.Sleep(500);
  74. DxHelper.WaitHelper.UpdateSplashMessage("正在初始化...");
  75. Thread.Sleep(1000);
  76. System.Windows.Forms.Application.Run(mainForm);
  77. }
  78. }
  79. }