Преглед на файлове

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

tanghai преди 2 години
родител
ревизия
c0caa9b1fd
променени са 4 файла, в които са добавени 12 реда и са изтрити 5 реда
  1. 3 1
      DotNet/Loader/Init.cs
  2. 2 1
      Share/Tool/Init.cs
  3. 1 1
      Unity/Assets/Scripts/Core/Fiber/Fiber.cs
  4. 6 2
      Unity/Assets/Scripts/Core/World/Module/Log/NLogger.cs

+ 3 - 1
DotNet/Loader/Init.cs

@@ -19,7 +19,9 @@ namespace ET
 				Parser.Default.ParseArguments<Options>(System.Environment.GetCommandLineArgs())
 				Parser.Default.ParseArguments<Options>(System.Environment.GetCommandLineArgs())
 						.WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
 						.WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
 						.WithParsed((o)=>World.Instance.AddSingleton(o));
 						.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;
 				ETTask.ExceptionHandler += Log.Error;
 				World.Instance.AddSingleton<TimeInfo>();
 				World.Instance.AddSingleton<TimeInfo>();
 				World.Instance.AddSingleton<FiberManager>();
 				World.Instance.AddSingleton<FiberManager>();

+ 2 - 1
Share/Tool/Init.cs

@@ -21,7 +21,8 @@ namespace ET.Server
                 Parser.Default.ParseArguments<Options>(args)
                 Parser.Default.ParseArguments<Options>(args)
                     .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
                     .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
                     .WithParsed((o)=>World.Instance.AddSingleton(o));
                     .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<CodeTypes, Assembly[]>(new[] { typeof (Init).Assembly });
                 World.Instance.AddSingleton<EventSystem>();
                 World.Instance.AddSingleton<EventSystem>();

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

@@ -61,7 +61,7 @@ namespace ET
 #if UNITY
 #if UNITY
             this.Log = Logger.Instance.Log;
             this.Log = Logger.Instance.Log;
 #else
 #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
 #endif
             this.Root = new Scene(this, id, 1, sceneType, name);
             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;
         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;
             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}");
             this.logger = LogManager.GetLogger($"{(uint)process:000000}.{(uint)fiber:0000000000}.{name}");
         }
         }