Sfoglia il codice sorgente

NLog现在一个fiber一个,所以LogManager.Configuration的调用不能放到NLog构造函数中了,不然存在多次赋值

tanghai 2 anni fa
parent
commit
c0caa9b1fd

+ 3 - 1
DotNet/Loader/Init.cs

@@ -19,7 +19,9 @@ namespace ET
 				Parser.Default.ParseArguments<Options>(System.Environment.GetCommandLineArgs())
 						.WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
 						.WithParsed((o)=>World.Instance.AddSingleton(o));
-				World.Instance.AddSingleton<Logger>().Log = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, 0, "../Config/NLog/NLog.config");
+				
+				World.Instance.AddSingleton<Logger>().Log = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, 0);
+				
 				ETTask.ExceptionHandler += Log.Error;
 				World.Instance.AddSingleton<TimeInfo>();
 				World.Instance.AddSingleton<FiberManager>();

+ 2 - 1
Share/Tool/Init.cs

@@ -21,7 +21,8 @@ namespace ET.Server
                 Parser.Default.ParseArguments<Options>(args)
                     .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
                     .WithParsed((o)=>World.Instance.AddSingleton(o));
-                World.Instance.AddSingleton<Logger>().Log = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, 0, "../Config/NLog/NLog.config");
+                
+                World.Instance.AddSingleton<Logger>().Log = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, 0);
                 
                 World.Instance.AddSingleton<CodeTypes, Assembly[]>(new[] { typeof (Init).Assembly });
                 World.Instance.AddSingleton<EventSystem>();

+ 1 - 1
Unity/Assets/Scripts/Core/Fiber/Fiber.cs

@@ -61,7 +61,7 @@ namespace ET
 #if UNITY
             this.Log = Logger.Instance.Log;
 #else
-            this.Log = new NLogger(sceneType.ToString(), this.Process, this.Id, "../Config/NLog/NLog.config");
+            this.Log = new NLogger(sceneType.ToString(), this.Process, this.Id);
 #endif
             this.Root = new Scene(this, id, 1, sceneType, name);
         }

+ 6 - 2
Unity/Assets/Scripts/Core/World/Module/Log/NLogger.cs

@@ -7,10 +7,14 @@ namespace ET
     {
         private readonly NLog.Logger logger;
 
-        public NLogger(string name, int process, int fiber, string configPath)
+        static NLogger()
         {
-            LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(configPath);
+            LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("../Config/NLog/NLog.config");
             LogManager.Configuration.Variables["currentDir"] = Environment.CurrentDirectory;
+        }
+
+        public NLogger(string name, int process, int fiber)
+        {
             this.logger = LogManager.GetLogger($"{(uint)process:000000}.{(uint)fiber:0000000000}.{name}");
         }