Program.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Threading;
  3. using CommandLine;
  4. using NLog;
  5. namespace ET
  6. {
  7. internal static class Program
  8. {
  9. private static int Main(string[] args)
  10. {
  11. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  12. {
  13. Log.Error(e.ExceptionObject.ToString());
  14. };
  15. // 异步方法全部会回掉到主线程
  16. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  17. try
  18. {
  19. Game.EventSystem.Add(typeof(Game).Assembly);
  20. ProtobufHelper.Init();
  21. MongoRegister.Init();
  22. // 命令行参数
  23. Options options = null;
  24. Parser.Default.ParseArguments<Options>(args)
  25. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  26. .WithParsed(o => { options = o; });
  27. Options.Instance = options;
  28. Log.ILog = new NLogger(Game.Options.AppType.ToString());
  29. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
  30. Log.Info($"server start........................ {Game.Scene.Id}");
  31. switch (Game.Options.AppType)
  32. {
  33. case AppType.ExcelExporter:
  34. {
  35. Game.Options.Console = 1;
  36. ExcelExporter.Export();
  37. return 0;
  38. }
  39. case AppType.Proto2CS:
  40. {
  41. Game.Options.Console = 1;
  42. Proto2CS.Export();
  43. return 0;
  44. }
  45. }
  46. }
  47. catch (Exception e)
  48. {
  49. Log.Console(e.ToString());
  50. }
  51. return 1;
  52. }
  53. }
  54. }