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