Init.cs 858 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using CommandLine;
  4. using MemoryPack;
  5. namespace ET
  6. {
  7. public static class Init
  8. {
  9. public static void Start()
  10. {
  11. try
  12. {
  13. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  14. {
  15. Log.Error(e.ExceptionObject.ToString());
  16. };
  17. // 命令行参数
  18. Parser.Default.ParseArguments<Options>(System.Environment.GetCommandLineArgs())
  19. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  20. .WithParsed(World.Instance.AddSingleton);
  21. World.Instance.AddSingleton<Logger>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
  22. ETTask.ExceptionHandler += Log.Error;
  23. World.Instance.AddSingleton<CodeLoader>();
  24. }
  25. catch (Exception e)
  26. {
  27. Log.Error(e);
  28. }
  29. }
  30. }
  31. }