Program.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 XdCxRhDW
  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. }
  31. /// <summary>
  32. /// 应用程序的主入口点。
  33. /// </summary>
  34. [STAThread]
  35. static void Main()
  36. {
  37. Serilog.Log.Logger = new Serilog.LoggerConfiguration()
  38. .WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
  39. .WriteTo.Logger(p => p.Filter.ByIncludingOnly(e => e.Level == Serilog.Events.LogEventLevel.Information)
  40. .WriteTo.File("Logs\\Info\\.log", rollingInterval: Serilog.RollingInterval.Day))
  41. .WriteTo.Logger(p => p.Filter.ByIncludingOnly(e => e.Level == Serilog.Events.LogEventLevel.Warning)
  42. .WriteTo.File("Logs\\Warning\\.log", rollingInterval: Serilog.RollingInterval.Day))
  43. .WriteTo.Logger(p => p.Filter.ByIncludingOnly(e => e.Level == Serilog.Events.LogEventLevel.Error)
  44. .WriteTo.File("Logs\\Error\\.log", rollingInterval: Serilog.RollingInterval.Day))
  45. .CreateLogger();
  46. WindowsFormsSettings.AllowDpiScale = true;
  47. WindowsFormsSettings.AllowHoverAnimation = DevExpress.Utils.DefaultBoolean.True;
  48. WindowsFormsSettings.AllowDefaultSvgImages = DevExpress.Utils.DefaultBoolean.True;
  49. WindowsFormsSettings.AllowRoundedWindowCorners = DevExpress.Utils.DefaultBoolean.True;
  50. WindowsFormsSettings.AnimationMode = AnimationMode.EnableAll;
  51. WindowsFormsSettings.BackgroundSkinningMode = BackgroundSkinningMode.AllColors;
  52. WindowsFormsSettings.DefaultAllowHtmlDraw = true;
  53. WindowsFormsSettings.DefaultLookAndFeel.SetSkinStyle(SkinStyle.WXICompact);
  54. WindowsFormsSettings.DefaultFont = new System.Drawing.Font("微软雅黑", 10f);
  55. WindowsFormsSettings.SetPerMonitorDpiAware();
  56. if (Debugger.IsAttached)
  57. {
  58. //DevExpress23.2以上版本查看未本地化的资源
  59. //DevExpress.Utils.Localization.XtraLocalizer.EnableTraceSource();
  60. }
  61. string screenTitle = ConfigurationManager.AppSettings["SystemName"];
  62. string screenCompany = ConfigurationManager.AppSettings["Company"];
  63. DxHelper.WaitHelper.SetSplashTips("Tips.txt");
  64. ChsLocalizer.UseChs();
  65. DxHelper.WaitHelper.ShowSplashScreen(screenTitle, screenCompany);
  66. DxHelper.WaitHelper.UpdateSplashMessage("正在加载程序资源文件...");
  67. MainForm mainForm = new MainForm() { Text = screenTitle };
  68. Thread.Sleep(500);
  69. DxHelper.WaitHelper.UpdateSplashMessage("正在初始化...");
  70. Thread.Sleep(1000);
  71. System.Windows.Forms.Application.Run(mainForm);
  72. }
  73. }
  74. }