Преглед изворни кода

增加FiberLog,每个Fiber都独立log文件

tanghai пре 2 година
родитељ
комит
5c435fd2ac
53 измењених фајлова са 412 додато и 389 уклоњено
  1. 13 27
      Config/NLog/NLog.config
  2. 1 1
      DotNet/Loader/Init.cs
  3. 1 1
      Share/Tool/Init.cs
  4. 2 2
      Unity/Assets/Resources/GlobalConfig.asset
  5. 2 2
      Unity/Assets/Scripts/Core/Entity/Scene.cs
  6. 7 1
      Unity/Assets/Scripts/Core/Fiber/Fiber.cs
  7. 6 0
      Unity/Assets/Scripts/Core/Network/AService.cs
  8. 12 3
      Unity/Assets/Scripts/Core/Network/KChannel.cs
  9. 2 2
      Unity/Assets/Scripts/Core/Network/KService.cs
  10. 10 2
      Unity/Assets/Scripts/Core/Network/TChannel.cs
  11. 4 4
      Unity/Assets/Scripts/Core/Network/TService.cs
  12. 10 2
      Unity/Assets/Scripts/Core/Network/WChannel.cs
  13. 2 2
      Unity/Assets/Scripts/Core/Network/WService.cs
  14. 118 0
      Unity/Assets/Scripts/Core/World/Module/Log/FiberLog.cs
  15. 1 1
      Unity/Assets/Scripts/Core/World/Module/Log/FiberLog.cs.meta
  16. 12 6
      Unity/Assets/Scripts/Core/World/Module/Log/ILog.cs
  17. 65 25
      Unity/Assets/Scripts/Core/World/Module/Log/Log.cs
  18. 7 149
      Unity/Assets/Scripts/Core/World/Module/Log/Logger.cs
  19. 17 20
      Unity/Assets/Scripts/Core/World/Module/Log/NLogger.cs
  20. 1 1
      Unity/Assets/Scripts/Editor/Helper/EditorLogHelper.cs
  21. 2 2
      Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_Attack.cs
  22. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_XunLuo.cs
  23. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Main2NetClient_LoginHandler.cs
  24. 2 2
      Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Ping/PingComponentSystem.cs
  25. 4 3
      Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterAddressComponentSystem.cs
  26. 4 4
      Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterCheckComponentSystem.cs
  27. 9 10
      Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterHelper.cs
  28. 4 3
      Unity/Assets/Scripts/Hotfix/Client/LockStep/LSClientHelper.cs
  29. 5 5
      Unity/Assets/Scripts/Hotfix/Client/LockStep/OneFrameInputsHandler.cs
  30. 3 2
      Unity/Assets/Scripts/Hotfix/Client/LockStep/Room2C_CheckHashFailHandler.cs
  31. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs
  32. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Benchmark/C2G_BenchmarkHandler.cs
  33. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Realm/C2R_LoginHandler.cs
  34. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Robot/Console/CreateRobotConsoleHandler.cs
  35. 7 7
      Unity/Assets/Scripts/Hotfix/Server/Demo/Robot/RobotConsoleHandler.cs
  36. 8 8
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationOneTypeSystem.cs
  37. 12 8
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs
  38. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/MessageLocationSenderComponentSystem.cs
  39. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/MessageLocationSenderSystem.cs
  40. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/MessageOuterSenderSystem.cs
  41. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs
  42. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/RobotCase/ARobotCase.cs
  43. 34 33
      Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs
  44. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionIdleCheckerComponentSystem.cs
  45. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Recast/PathfindingComponentSystem.cs
  46. 3 2
      Unity/Assets/Scripts/HotfixView/Client/Demo/UI/UILobby/UILobbyComponentSystem.cs
  47. 1 1
      Unity/Assets/Scripts/HotfixView/Client/LockStep/UI/UILSLobby/UILSLobbyComponentSystem.cs
  48. 1 1
      Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs
  49. 0 27
      Unity/Assets/Scripts/Model/Server/Module/RobotCase/RobotLog.cs
  50. 1 1
      Unity/Assets/Scripts/Model/Share/LockStep/LSWorld.cs
  51. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Message/LogMsg.cs
  52. 2 2
      Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs
  53. 2 2
      Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesComponent.cs

+ 13 - 27
Config/NLog/NLog.config

@@ -8,8 +8,8 @@
 				archiveNumbering="Date"
 				archiveEvery="Hour"
 				archiveDateFormat="yyyyMMddHH"
-				archiveFileName="${basedir}/../Logs/${logger}.${var:appIdFormat}.{#}.Debug.log"
-				fileName="${basedir}/../Logs/${logger}.${var:appIdFormat}.${date:format=yyyyMMddHH}.Debug.log"
+				archiveFileName="${basedir}/../Logs/${logger}.{#}.${var:fiberName}.Debug.log"
+				fileName="${basedir}/../Logs/${logger}.${date:format=yyyyMMddHH}.${var:fiberName}.Debug.log"
 				deleteOldFileOnStartup="false"
 				layout="${longdate} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=3} ${message}" />
 	</targets>
@@ -22,8 +22,8 @@
 				archiveNumbering="Date"
 				archiveEvery="Hour"
 				archiveDateFormat="yyyyMMddHH"
-				archiveFileName="${basedir}/../Logs/${logger}.${var:appIdFormat}.{#}.Info.log"
-				fileName="${basedir}/../Logs/${logger}.${var:appIdFormat}.${date:format=yyyyMMddHH}.Info.log"
+				archiveFileName="${basedir}/../Logs/${logger}.{#}.${var:fiberName}.Info.log"
+				fileName="${basedir}/../Logs/${logger}.${date:format=yyyyMMddHH}.${var:fiberName}.Info.log"
 				deleteOldFileOnStartup="false"
 				layout="${longdate} ${message}" />
 	</targets>
@@ -36,8 +36,8 @@
 				archiveNumbering="Date"
 				archiveEvery="Hour"
 				archiveDateFormat="yyyyMMddHH"
-				archiveFileName="${basedir}/../Logs/${logger}.${var:appIdFormat}.{#}.Warn.log"
-				fileName="${basedir}/../Logs/${logger}.${var:appIdFormat}.${date:format=yyyyMMddHH}.Warn.log"
+				archiveFileName="${basedir}/../Logs/${logger}.{#}.${var:fiberName}.Warn.log"
+				fileName="${basedir}/../Logs/${logger}.${date:format=yyyyMMddHH}.${var:fiberName}.Warn.log"
 				deleteOldFileOnStartup="false"
 				layout="${longdate} ${message}" />
 	</targets>
@@ -49,8 +49,8 @@
 				archiveNumbering="Date"
 				archiveEvery="Hour"
 				archiveDateFormat="yyyyMMddHH"
-				archiveFileName="${basedir}/../Logs/${logger}.${var:appIdFormat}.{#}.Error.log"
-				fileName="${basedir}/../Logs/${logger}.${var:appIdFormat}.${date:format=yyyyMMddHH}.Error.log"
+				archiveFileName="${basedir}/../Logs/${logger}.{#}.${var:fiberName}.Error.log"
+				fileName="${basedir}/../Logs/${logger}.${date:format=yyyyMMddHH}.${var:fiberName}.Error.log"
 				deleteOldFileOnStartup="false"
 				layout="${longdate} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=3} ${message}" />
 	</targets>
@@ -59,25 +59,11 @@
 		<target name="ErrorConsole" xsi:type="Console" layout="${longdate} ${message}" />
 	</targets>
 
-	<targets async="true">
-		<target name="Watcher" xsi:type="File"
-				openFileCacheTimeout="10"
-				keepFileOpen="true"
-				fileName="${basedir}/../Logs/${logger}.${var:appIdFormat}.Debug.log"
-				deleteOldFileOnStartup="false"
-				layout="${longdate} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=3} ${message}" />
-	</targets>
-
-	<targets async="true">
-		<target name="RobotConsole" xsi:type="Console" layout="${message}" />
-	</targets>
-
 	<rules>
-		<logger ruleName="ServerDebug" name="Server" minlevel="Trace" maxlevel="Error" writeTo="ServerDebug" />
-		<logger ruleName="ServerInfo" name="Server" minlevel="Info" maxlevel="Info" writeTo="ServerInfo" />
-		<logger ruleName="ServerWarn" name="Server" minlevel="Warn" maxlevel="Warn" writeTo="ServerWarn" />
-		<logger ruleName="ServerError" name="Server" minlevel="Error" maxlevel="Error" writeTo="ServerError" />
-		<logger ruleName="ErrorConsole" name="Server" minlevel="Warn" maxlevel="Error" writeTo="ErrorConsole" />
-		<logger ruleName="Watcher" name="Watcher" minlevel="Trace" maxlevel="Error" writeTo="Watcher" />
+		<logger ruleName="ServerDebug" name="*" minlevel="Trace" maxlevel="Error" writeTo="ServerDebug" />
+		<logger ruleName="ServerInfo" name="*" minlevel="Info" maxlevel="Info" writeTo="ServerInfo" />
+		<logger ruleName="ServerWarn" name="*" minlevel="Warn" maxlevel="Warn" writeTo="ServerWarn" />
+		<logger ruleName="ServerError" name="*" minlevel="Error" maxlevel="Error" writeTo="ServerError" />
+		<logger ruleName="ErrorConsole" name="*" minlevel="Warn" maxlevel="Error" writeTo="ErrorConsole" />
 	</rules>
 </nlog>

+ 1 - 1
DotNet/Loader/Init.cs

@@ -19,7 +19,7 @@ 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>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
+				World.Instance.AddSingleton<Logger>().Log = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, 0, "../Config/NLog/NLog.config");
 				ETTask.ExceptionHandler += Log.Error;
 
 				World.Instance.AddSingleton<CodeLoader>();

+ 1 - 1
Share/Tool/Init.cs

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

+ 2 - 2
Unity/Assets/Resources/GlobalConfig.asset

@@ -12,6 +12,6 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 36527db572638af47b03c805671cba75, type: 3}
   m_Name: GlobalConfig
   m_EditorClassIdentifier: 
-  CodeMode: 3
+  CodeMode: 1
   BuildType: 1
-  AppType: 8
+  AppType: 7

+ 2 - 2
Unity/Assets/Scripts/Core/Entity/Scene.cs

@@ -33,14 +33,14 @@ namespace ET
             this.Fiber = fiber;
             this.IScene = this;
             this.IsRegister = true;
-            Log.Info($"scene create: {this.SceneType} {this.Id} {this.InstanceId}");
+            fiber.Info($"scene create: {this.SceneType} {this.Id} {this.InstanceId}");
         }
 
         public override void Dispose()
         {
             base.Dispose();
             
-            Log.Info($"scene dispose: {this.SceneType} {this.Id} {this.InstanceId}");
+            this.Fiber.Info($"scene dispose: {this.SceneType} {this.Id} {this.InstanceId}");
         }
         
         protected override string ViewName

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

@@ -42,6 +42,7 @@ namespace ET
         public EntitySystem EntitySystem { get; }
         public Mailboxes Mailboxes { get; private set; }
         public ThreadSynchronizationContext ThreadSynchronizationContext { get; }
+        public ILog Log { get; }
         
         private EntityRef<TimerComponent> timerCompnent;
         public TimerComponent TimerComponent
@@ -91,6 +92,11 @@ namespace ET
             this.EntitySystem = new EntitySystem();
             this.Mailboxes = new Mailboxes();
             this.ThreadSynchronizationContext = new ThreadSynchronizationContext();
+#if UNITY
+            this.Log = Logger.Instance.Log;
+#else
+            this.Log = new NLogger(sceneType.ToString(), this.Process, this.Id, "../Config/NLog/NLog.config");
+#endif
             this.Root = new Scene(this, id, 1, sceneType, name);
         }
 
@@ -102,7 +108,7 @@ namespace ET
             }
             catch (Exception e)
             {
-                Log.Error(e);
+                this.Log.Error(e);
             }
         }
         

+ 6 - 0
Unity/Assets/Scripts/Core/Network/AService.cs

@@ -7,6 +7,7 @@ namespace ET
 {
     public abstract class AService: IDisposable
     {
+        public ILog Log;
         public Action<long, IPEndPoint> AcceptCallback;
         public Action<long, ActorId, object> ReadCallback;
         public Action<long, int> ErrorCallback;
@@ -19,6 +20,11 @@ namespace ET
 		
         private readonly Queue<MemoryBuffer> pool = new();
 
+        protected AService(ILog log)
+        {
+            this.Log = log;
+        }
+
         public MemoryBuffer Fetch(int size = 0)
         {
             if (size > MaxMemoryBufferSize)

+ 12 - 3
Unity/Assets/Scripts/Core/Network/KChannel.cs

@@ -30,6 +30,15 @@ namespace ET
 				this.Id = value;
 			}
 		}
+
+		private ILog Log
+		{
+			get
+			{
+				return this.Service.Log;
+			}
+		}
+		
 		public uint RemoteConn { get; set; }
 
 		private readonly byte[] sendCache = new byte[2 * 1024];
@@ -80,12 +89,13 @@ namespace ET
 		// connect
 		public KChannel(uint localConn, IPEndPoint remoteEndPoint, KService kService)
 		{
+			this.Service = kService;
 			this.LocalConn = localConn;
 			this.ChannelType = ChannelType.Connect;
 			
 			Log.Info($"channel create: {this.LocalConn} {remoteEndPoint} {this.ChannelType}");
 			
-			this.Service = kService;
+			
 			this.RemoteAddress = remoteEndPoint;
 			this.CreateTime = kService.TimeNow;
 
@@ -96,11 +106,10 @@ namespace ET
 		// accept
 		public KChannel(uint localConn, uint remoteConn, IPEndPoint remoteEndPoint, KService kService)
 		{
+			this.Service = kService;
 			this.ChannelType = ChannelType.Accept;
 			
 			Log.Info($"channel create: {localConn} {remoteConn} {remoteEndPoint} {this.ChannelType}");
-
-			this.Service = kService;
 			this.LocalConn = localConn;
 			this.RemoteConn = remoteConn;
 			this.RemoteAddress = remoteEndPoint;

+ 2 - 2
Unity/Assets/Scripts/Core/Network/KService.cs

@@ -46,7 +46,7 @@ namespace ET
 
         public Socket Socket;
 
-        public KService(IPEndPoint ipEndPoint, ServiceType serviceType)
+        public KService(IPEndPoint ipEndPoint, ServiceType serviceType, ILog log): base(log)
         {
             this.ServiceType = serviceType;
             this.startTime = DateTime.UtcNow.Ticks;
@@ -70,7 +70,7 @@ namespace ET
             NetworkHelper.SetSioUdpConnReset(this.Socket);
         }
 
-        public KService(AddressFamily addressFamily, ServiceType serviceType)
+        public KService(AddressFamily addressFamily, ServiceType serviceType, ILog log): base(log)
         {
             this.ServiceType = serviceType;
             this.startTime = DateTime.UtcNow.Ticks;

+ 10 - 2
Unity/Assets/Scripts/Core/Network/TChannel.cs

@@ -27,6 +27,14 @@ namespace ET
 		public IPEndPoint RemoteAddress { get; set; }
 
 		private readonly byte[] sendCache = new byte[Packet.OpcodeLength + Packet.ActorIdLength];
+		
+		private ILog Log
+		{
+			get
+			{
+				return this.Service.Log;
+			}
+		}
 
 		private void OnComplete(object sender, SocketAsyncEventArgs e)
 		{
@@ -35,9 +43,9 @@ namespace ET
 		
 		public TChannel(long id, IPEndPoint ipEndPoint, TService service)
 		{
+			this.Service = service;
 			this.ChannelType = ChannelType.Connect;
 			this.Id = id;
-			this.Service = service;
 			this.socket = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
 			this.socket.NoDelay = true;
 			this.parser = new PacketParser(this.recvBuffer, this.Service);
@@ -53,9 +61,9 @@ namespace ET
 		
 		public TChannel(long id, Socket socket, TService service)
 		{
+			this.Service = service;
 			this.ChannelType = ChannelType.Accept;
 			this.Id = id;
-			this.Service = service;
 			this.socket = socket;
 			this.socket.NoDelay = true;
 			this.parser = new PacketParser(this.recvBuffer, this.Service);

+ 4 - 4
Unity/Assets/Scripts/Core/Network/TService.cs

@@ -32,12 +32,12 @@ namespace ET
 
 		public ConcurrentQueue<TArgs> Queue = new();
 
-		public TService(AddressFamily addressFamily, ServiceType serviceType)
+		public TService(AddressFamily addressFamily, ServiceType serviceType, ILog log): base(log)
 		{
 			this.ServiceType = serviceType;
 		}
 
-		public TService(IPEndPoint ipEndPoint, ServiceType serviceType)
+		public TService(IPEndPoint ipEndPoint, ServiceType serviceType, ILog log): base(log)
 		{
 			this.ServiceType = serviceType;
 			this.acceptor = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
@@ -92,9 +92,9 @@ namespace ET
 				
 				this.AcceptCallback(channelId, channel.RemoteAddress);
 			}
-			catch (Exception exception)
+			catch (Exception e)
 			{
-				Log.Error(exception);
+				Log.Error(e);
 			}		
 			
 			// 开始新的accept

+ 10 - 2
Unity/Assets/Scripts/Core/Network/WChannel.cs

@@ -24,11 +24,19 @@ namespace ET
         public IPEndPoint RemoteAddress { get; set; }
 
         private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
+        
+        private ILog Log
+        {
+            get
+            {
+                return this.Service.Log;
+            }
+        }
 
         public WChannel(long id, HttpListenerWebSocketContext webSocketContext, WService service)
         {
-            this.Id = id;
             this.Service = service;
+            this.Id = id;
             this.ChannelType = ChannelType.Accept;
             this.WebSocketContext = webSocketContext;
             this.webSocket = webSocketContext.WebSocket;
@@ -44,8 +52,8 @@ namespace ET
 
         public WChannel(long id, WebSocket webSocket, string connectUrl, WService service)
         {
-            this.Id = id;
             this.Service = service;
+            this.Id = id;
             this.ChannelType = ChannelType.Connect;
             this.webSocket = webSocket;
 

+ 2 - 2
Unity/Assets/Scripts/Core/Network/WService.cs

@@ -16,7 +16,7 @@ namespace ET
 
         public ThreadSynchronizationContext ThreadSynchronizationContext;
 
-        public WService(IEnumerable<string> prefixs)
+        public WService(IEnumerable<string> prefixs, ILog log): base(log)
         {
             this.ThreadSynchronizationContext = new ThreadSynchronizationContext();
             
@@ -25,7 +25,7 @@ namespace ET
             StartAccept(prefixs).Coroutine();
         }
         
-        public WService()
+        public WService(ILog log): base(log)
         {
             this.ThreadSynchronizationContext = new ThreadSynchronizationContext();
         }

+ 118 - 0
Unity/Assets/Scripts/Core/World/Module/Log/FiberLog.cs

@@ -0,0 +1,118 @@
+using System;
+using System.Diagnostics;
+
+namespace ET
+{
+    public static class FiberLog
+    {
+        private const int TraceLevel = 1;
+        private const int DebugLevel = 2;
+        private const int InfoLevel = 3;
+        private const int WarningLevel = 4;
+        
+        private static bool CheckLogLevel(int level)
+        {
+            if (Options.Instance == null)
+            {
+                return true;
+            }
+            return Options.Instance.LogLevel <= level;
+        }
+        
+        [Conditional("DEBUG")]
+        public static void Debug(this Fiber self, string msg)
+        {
+            if (!CheckLogLevel(DebugLevel))
+            {
+                return;
+            }
+            self.Log.Debug(msg);
+        }
+        
+        [Conditional("DEBUG")]
+        public static void Trace(this Fiber self, string msg)
+        {
+            if (!CheckLogLevel(TraceLevel))
+            {
+                return;
+            }
+            
+            self.Log.Trace(msg);
+        }
+
+        public static void Info(this Fiber self, string msg)
+        {
+            if (!CheckLogLevel(InfoLevel))
+            {
+                return;
+            }
+            self.Log.Info(msg);
+        }
+
+        public static void TraceInfo(this Fiber self, string msg)
+        {
+            if (!CheckLogLevel(InfoLevel))
+            {
+                return;
+            }
+            self.Log.Trace(msg);
+        }
+
+        public static void Warning(this Fiber self, string msg)
+        {
+            if (!CheckLogLevel(WarningLevel))
+            {
+                return;
+            }
+
+            self.Log.Warning(msg);
+        }
+
+        public static void Error(this Fiber self, string msg)
+        {
+            self.Log.Error(msg);
+        }
+
+        public static void Error(this Fiber self, Exception e)
+        {
+            self.Log.Error(e.ToString());
+        }
+        
+        public static void Console(this Fiber self, string msg)
+        {
+            if (Options.Instance.Console == 1)
+            {
+                System.Console.WriteLine(msg);
+            }
+            self.Log.Debug(msg);
+        }
+
+#if DOTNET
+        [Conditional("DEBUG")]
+        public static void Trace(this Fiber self, ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
+        {
+            self.Log.Trace(ref message);
+        }
+        [Conditional("DEBUG")]
+        public static void Warning(this Fiber self, ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
+        {
+            self.Log.Warning(ref message);
+        }
+
+        public static void Info(this Fiber self, ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
+        {
+            self.Log.Info(ref message);
+        }
+        [Conditional("DEBUG")]
+        public static void Debug(this Fiber self, ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
+        {
+            self.Log.Debug(ref message);
+        }
+
+        public static void Error(this Fiber self, ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
+        {
+            self.Log.Error(ref message);
+        }
+#endif
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/RobotCase/RobotLog.cs.meta → Unity/Assets/Scripts/Core/World/Module/Log/FiberLog.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 0d2320c977663dc45b2fa20ca780ae4d
+guid: 0357cabeaecc01a469c570e5c84b844c
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 12 - 6
Unity/Assets/Scripts/Core/World/Module/Log/ILog.cs

@@ -1,4 +1,6 @@
-namespace ET
+using System;
+
+namespace ET
 {
     public interface ILog
     {
@@ -7,10 +9,14 @@
         void Info(string message);
         void Debug(string message);
         void Error(string message);
-        void Trace(string message, params object[] args);
-        void Warning(string message, params object[] args);
-        void Info(string message, params object[] args);
-        void Debug(string message, params object[] args);
-        void Error(string message, params object[] args);
+        void Error(Exception e);
+
+#if DOTNET
+        public void Trace(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message);
+        public void Warning(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message);
+        public void Info(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message);
+        public void Debug(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message);
+        public void Error(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message);
+#endif
     }
 }

+ 65 - 25
Unity/Assets/Scripts/Core/World/Module/Log/Log.cs

@@ -5,75 +5,115 @@ namespace ET
 {
     public static class Log
     {
-        [Conditional("DEBUG")]
-        public static void Trace(string msg)
+        private const int TraceLevel = 1;
+        private const int DebugLevel = 2;
+        private const int InfoLevel = 3;
+        private const int WarningLevel = 4;
+        
+        private static bool CheckLogLevel(int level)
         {
-            Logger.Instance.Trace(msg);
+            if (Options.Instance == null)
+            {
+                return true;
+            }
+            return Options.Instance.LogLevel <= level;
         }
-
+        
         [Conditional("DEBUG")]
         public static void Debug(string msg)
         {
-            Logger.Instance.Debug(msg);
+            if (!CheckLogLevel(DebugLevel))
+            {
+                return;
+            }
+            Logger.Instance.Log.Debug(msg);
+        }
+        
+        [Conditional("DEBUG")]
+        public static void Trace(string msg)
+        {
+            if (!CheckLogLevel(TraceLevel))
+            {
+                return;
+            }
+            StackTrace st = new(1, true);
+            Logger.Instance.Log.Trace($"{msg}\n{st}");
         }
 
         public static void Info(string msg)
         {
-            Logger.Instance.Info(msg);
+            if (!CheckLogLevel(InfoLevel))
+            {
+                return;
+            }
+            Logger.Instance.Log.Info(msg);
+        }
+
+        public static void TraceInfo(string msg)
+        {
+            if (!CheckLogLevel(InfoLevel))
+            {
+                return;
+            }
+            StackTrace st = new(1, true);
+            Logger.Instance.Log.Trace($"{msg}\n{st}");
         }
 
-        [Conditional("DEBUG")]
         public static void Warning(string msg)
         {
-            Logger.Instance.Warning(msg);
+            if (!CheckLogLevel(WarningLevel))
+            {
+                return;
+            }
+
+            Logger.Instance.Log.Warning(msg);
         }
 
         public static void Error(string msg)
         {
-            Logger.Instance.Error(msg);
+            StackTrace st = new(1, true);
+            Logger.Instance.Log.Error($"{msg}\n{st}");
         }
 
-        public static void Error(Exception msg)
+        public static void Error(Exception e)
         {
-            Logger.Instance.Error(msg);
+            Logger.Instance.Log.Error(e.ToString());
         }
-
-        [Conditional("DEBUG")]
+        
         public static void Console(string msg)
         {
-            Logger.Instance.Console(msg);
+            if (Options.Instance.Console == 1)
+            {
+                System.Console.WriteLine(msg);
+            }
+            Logger.Instance.Log.Debug(msg);
         }
-        
+
 #if DOTNET
         [Conditional("DEBUG")]
         public static void Trace(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            Logger.Instance.Trace(message.ToStringAndClear());
+            Logger.Instance.Log.Trace(ref message);
         }
         [Conditional("DEBUG")]
         public static void Warning(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            Logger.Instance.Warning(message.ToStringAndClear());
+            Logger.Instance.Log.Warning(ref message);
         }
 
         public static void Info(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            Logger.Instance.Info(message.ToStringAndClear());
+            Logger.Instance.Log.Info(ref message);
         }
         [Conditional("DEBUG")]
         public static void Debug(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            Logger.Instance.Debug(message.ToStringAndClear());
+            Logger.Instance.Log.Debug(ref message);
         }
 
         public static void Error(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            Logger.Instance.Error(message.ToStringAndClear());
-        }
-        [Conditional("DEBUG")]
-        public static void Console(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
-        {
-            Logger.Instance.Console(message.ToStringAndClear());
+            Logger.Instance.Log.Error(ref message);
         }
 #endif
     }

+ 7 - 149
Unity/Assets/Scripts/Core/World/Module/Log/Logger.cs

@@ -1,165 +1,23 @@
-using System;
-using System.Diagnostics;
-
-namespace ET
+namespace ET
 {
     public class Logger: Singleton<Logger>, ISingletonAwake
     {
-        private ILog iLog;
+        private ILog log;
 
-        public ILog ILog
+        public ILog Log
         {
             set
             {
-                this.iLog = value;
+                this.log = value;
             }
-        }
-        
-        private const int TraceLevel = 1;
-        private const int DebugLevel = 2;
-        private const int InfoLevel = 3;
-        private const int WarningLevel = 4;
-        
-        public void Awake()
-        {
-        }
-
-        private bool CheckLogLevel(int level)
-        {
-            if (Options.Instance == null)
+            get
             {
-                return true;
+                return this.log;
             }
-            return Options.Instance.LogLevel <= level;
         }
         
-        public void Trace(string msg)
-        {
-            if (!CheckLogLevel(DebugLevel))
-            {
-                return;
-            }
-            StackTrace st = new StackTrace(2, true);
-            this.iLog.Trace($"{msg}\n{st}");
-        }
-
-        public void Debug(string msg)
-        {
-            if (!CheckLogLevel(DebugLevel))
-            {
-                return;
-            }
-            this.iLog.Debug(msg);
-        }
-
-        public void Info(string msg)
-        {
-            if (!CheckLogLevel(InfoLevel))
-            {
-                return;
-            }
-            this.iLog.Info(msg);
-        }
-
-        public void TraceInfo(string msg)
-        {
-            if (!CheckLogLevel(InfoLevel))
-            {
-                return;
-            }
-            StackTrace st = new StackTrace(2, true);
-            this.iLog.Trace($"{msg}\n{st}");
-        }
-
-        public void Warning(string msg)
-        {
-            if (!CheckLogLevel(WarningLevel))
-            {
-                return;
-            }
-
-            this.iLog.Warning(msg);
-        }
-
-        public void Error(string msg)
-        {
-            StackTrace st = new StackTrace(2, true);
-            this.iLog.Error($"{msg}\n{st}");
-        }
-
-        public void Error(Exception e)
-        {
-            if (e.Data.Contains("StackTrace"))
-            {
-                this.iLog.Error($"{e.Data["StackTrace"]}\n{e}");
-                return;
-            }
-            string str = e.ToString();
-            this.iLog.Error(str);
-        }
-
-        public void Trace(string message, params object[] args)
-        {
-            if (!CheckLogLevel(TraceLevel))
-            {
-                return;
-            }
-            StackTrace st = new StackTrace(2, true);
-            this.iLog.Trace($"{string.Format(message, args)}\n{st}");
-        }
-
-        public void Warning(string message, params object[] args)
-        {
-            if (!CheckLogLevel(WarningLevel))
-            {
-                return;
-            }
-            this.iLog.Warning(string.Format(message, args));
-        }
-
-        public void Info(string message, params object[] args)
-        {
-            if (!CheckLogLevel(InfoLevel))
-            {
-                return;
-            }
-            this.iLog.Info(string.Format(message, args));
-        }
-
-        public void Debug(string message, params object[] args)
-        {
-            if (!CheckLogLevel(DebugLevel))
-            {
-                return;
-            }
-            this.iLog.Debug(string.Format(message, args));
-
-        }
-
-        public void Error(string message, params object[] args)
-        {
-            StackTrace st = new StackTrace(2, true);
-            string s = string.Format(message, args) + '\n' + st;
-            this.iLog.Error(s);
-        }
-        
-        public void Console(string message)
-        {
-            if (Options.Instance.Console == 1)
-            {
-                System.Console.WriteLine(message);
-            }
-            this.iLog.Debug(message);
-        }
-        
-        public void Console(string message, params object[] args)
+        public void Awake()
         {
-            string s = string.Format(message, args);
-            if (Options.Instance.Console == 1)
-            {
-                System.Console.WriteLine(s);
-            }
-            this.iLog.Debug(s);
         }
     }
 }

+ 17 - 20
Unity/Assets/Scripts/Core/World/Module/Log/NLogger.cs

@@ -7,12 +7,12 @@ namespace ET
     {
         private readonly NLog.Logger logger;
 
-        public NLogger(string name, int process, string configPath)
+        public NLogger(string name, int process, int fiber, string configPath)
         {
             LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(configPath);
-            LogManager.Configuration.Variables["appIdFormat"] = $"{process:000000}";
             LogManager.Configuration.Variables["currentDir"] = Environment.CurrentDirectory;
-            this.logger = LogManager.GetLogger(name);
+            LogManager.Configuration.Variables["fiberName"] = name;
+            this.logger = LogManager.GetLogger($"{(uint)process:000000}.{(uint)fiber:0000000000}");
         }
 
         public void Trace(string message)
@@ -40,39 +40,36 @@ namespace ET
             this.logger.Error(message);
         }
 
-        public void Fatal(string message)
+        public void Error(Exception e)
         {
-            this.logger.Fatal(message);
+            this.logger.Error(e.ToString());
         }
 
-        public void Trace(string message, params object[] args)
+#if DOTNET
+        public void Trace(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            this.logger.Trace(message, args);
+            this.logger.Trace(message.ToStringAndClear());
         }
 
-        public void Warning(string message, params object[] args)
+        public void Warning(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            this.logger.Warn(message, args);
+            this.logger.Warn(message.ToStringAndClear());
         }
 
-        public void Info(string message, params object[] args)
+        public void Info(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            this.logger.Info(message, args);
+            this.logger.Info(message.ToStringAndClear());
         }
 
-        public void Debug(string message, params object[] args)
+        public void Debug(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            this.logger.Debug(message, args);
+            this.logger.Debug(message.ToStringAndClear());
         }
 
-        public void Error(string message, params object[] args)
+        public void Error(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
-            this.logger.Error(message, args);
-        }
-
-        public void Fatal(string message, params object[] args)
-        {
-            this.logger.Fatal(message, args);
+            this.logger.Error(message.ToStringAndClear());
         }
+#endif
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Editor/Helper/EditorLogHelper.cs

@@ -44,7 +44,7 @@ namespace ET
                 return;
             }
 
-            World.Instance.AddSingleton<Logger>().ILog = new UnityLogger();
+            World.Instance.AddSingleton<Logger>().Log = new UnityLogger();
         }
 
         private static void DestroyLog()

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_Attack.cs

@@ -25,11 +25,11 @@ namespace ET.Client
             // 停在当前位置
             fiber.Root.GetComponent<ClientSenderCompnent>().Send(new C2M_Stop());
             
-            Log.Debug("开始攻击");
+            fiber.Debug("开始攻击");
 
             for (int i = 0; i < 100000; ++i)
             {
-                Log.Debug($"攻击: {i}次");
+                fiber.Debug($"攻击: {i}次");
 
                 // 因为协程可能被中断,任何协程都要传入cancellationToken,判断如果是中断则要返回
                 await fiber.TimerComponent.WaitAsync(1000, cancellationToken);

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_XunLuo.cs

@@ -24,7 +24,7 @@ namespace ET.Client
                 return;
             }
             
-            Log.Debug("开始巡逻");
+            root.Fiber().Debug("开始巡逻");
 
             while (true)
             {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Main2NetClient_LoginHandler.cs

@@ -35,7 +35,7 @@ namespace ET.Client
             root.AddComponent<SessionComponent>().Session = gateSession;
             G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await gateSession.Call(new C2G_LoginGate() { Key = r2CLogin.Key, GateId = r2CLogin.GateId });
 
-            Log.Debug("登陆gate成功!");
+            root.Fiber().Debug("登陆gate成功!");
 
             response.PlayerId = g2CLoginGate.PlayerId;
         }

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Ping/PingComponentSystem.cs

@@ -51,12 +51,12 @@ namespace ET.Client
                 catch (RpcException e)
                 {
                     // session断开导致ping rpc报错,记录一下即可,不需要打成error
-                    Log.Info($"ping error: {self.Id} {e.Error}");
+                    fiber.Info($"ping error: {self.Id} {e.Error}");
                     return;
                 }
                 catch (Exception e)
                 {
-                    Log.Error($"ping error: \n{e}");
+                    fiber.Error($"ping error: \n{e}");
                 }
             }
         }

+ 4 - 3
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterAddressComponentSystem.cs

@@ -24,13 +24,14 @@ namespace ET.Client
 
         private static async ETTask GetAllRouter(this RouterAddressComponent self)
         {
+            Fiber fiber = self.Fiber();
             string url = $"http://{self.RouterManagerHost}:{self.RouterManagerPort}/get_router?v={RandomGenerator.RandUInt32()}";
-            Log.Debug($"start get router info: {url}");
+            fiber.Debug($"start get router info: {url}");
             string routerInfo = await HttpClientHelper.Get(url);
-            Log.Debug($"recv router info: {routerInfo}");
+            fiber.Debug($"recv router info: {routerInfo}");
             HttpGetRouterResponse httpGetRouterResponse = MongoHelper.FromJson<HttpGetRouterResponse>(routerInfo);
             self.Info = httpGetRouterResponse;
-            Log.Debug($"start get router info finish: {MongoHelper.ToJson(httpGetRouterResponse)}");
+            fiber.Debug($"start get router info finish: {MongoHelper.ToJson(httpGetRouterResponse)}");
             
             // 打乱顺序
             RandomGenerator.BreakRank(self.Info.Routers);

+ 4 - 4
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterCheckComponentSystem.cs

@@ -46,16 +46,16 @@ namespace ET.Client
                     (uint localConn, uint remoteConn) = session.AService.GetChannelConn(sessionId);
                     
                     IPEndPoint realAddress = self.GetParent<Session>().RemoteAddress;
-                    Log.Info($"get recvLocalConn start: {root.Id} {realAddress} {localConn} {remoteConn}");
+                    fiber.Info($"get recvLocalConn start: {root.Id} {realAddress} {localConn} {remoteConn}");
 
                     (uint recvLocalConn, IPEndPoint routerAddress) = await RouterHelper.GetRouterAddress(root, realAddress, localConn, remoteConn);
                     if (recvLocalConn == 0)
                     {
-                        Log.Error($"get recvLocalConn fail: {root.Id} {routerAddress} {realAddress} {localConn} {remoteConn}");
+                        fiber.Error($"get recvLocalConn fail: {root.Id} {routerAddress} {realAddress} {localConn} {remoteConn}");
                         continue;
                     }
                     
-                    Log.Info($"get recvLocalConn ok: {root.Id} {routerAddress} {realAddress} {recvLocalConn} {localConn} {remoteConn}");
+                    fiber.Info($"get recvLocalConn ok: {root.Id} {routerAddress} {realAddress} {recvLocalConn} {localConn} {remoteConn}");
                     
                     session.LastRecvTime = TimeInfo.Instance.ClientNow();
                     
@@ -63,7 +63,7 @@ namespace ET.Client
                 }
                 catch (Exception e)
                 {
-                    Log.Error(e);
+                    fiber.Error(e);
                 }
             }
         }

+ 9 - 10
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterHelper.cs

@@ -16,7 +16,7 @@ namespace ET.Client
                 throw new Exception($"get router fail: {root.Id} {address}");
             }
             
-            Log.Info($"get router: {recvLocalConn} {routerAddress}");
+            root.Fiber().Info($"get router: {recvLocalConn} {routerAddress}");
 
             Session routerSession = root.GetComponent<NetClientComponent>().Create(routerAddress, address, recvLocalConn);
             routerSession.AddComponent<PingComponent>();
@@ -27,14 +27,14 @@ namespace ET.Client
         
         public static async ETTask<(uint, IPEndPoint)> GetRouterAddress(Scene root, IPEndPoint address, uint localConn, uint remoteConn)
         {
-            Log.Info($"start get router address: {root.Id} {address} {localConn} {remoteConn}");
+            root.Fiber().Info($"start get router address: {root.Id} {address} {localConn} {remoteConn}");
             //return (RandomHelper.RandUInt32(), address);
             RouterAddressComponent routerAddressComponent = root.GetComponent<RouterAddressComponent>();
             IPEndPoint routerInfo = routerAddressComponent.GetAddress();
             
             uint recvLocalConn = await Connect(root, routerInfo, address, localConn, remoteConn);
             
-            Log.Info($"finish get router address: {root.Id} {address} {localConn} {remoteConn} {recvLocalConn} {routerInfo}");
+            root.Fiber().Info($"finish get router address: {root.Id} {address} {localConn} {remoteConn} {recvLocalConn} {routerInfo}");
             return (recvLocalConn, routerInfo);
         }
 
@@ -56,14 +56,13 @@ namespace ET.Client
             sendCache.WriteTo(9, connectId);
             byte[] addressBytes = realAddress.ToString().ToByteArray();
             Array.Copy(addressBytes, 0, sendCache, 13, addressBytes.Length);
-
-            Log.Info($"router connect: {connectId} {localConn} {remoteConn} {routerAddress} {realAddress}");
+            Fiber fiber = root.Fiber;
+            fiber.Info($"router connect: {connectId} {localConn} {remoteConn} {routerAddress} {realAddress}");
                 
             EndPoint recvIPEndPoint = new IPEndPoint(IPAddress.Any, 0);
 
             long lastSendTimer = 0;
 
-            Fiber fiber = root.Fiber;
             while (true)
             {
                 long timeNow = TimeInfo.Instance.ClientFrameTime();
@@ -71,7 +70,7 @@ namespace ET.Client
                 {
                     if (--count < 0)
                     {
-                        Log.Error($"router connect timeout fail! {localConn} {remoteConn} {routerAddress} {realAddress}");
+                        fiber.Error($"router connect timeout fail! {localConn} {remoteConn} {routerAddress} {realAddress}");
                         return 0;
                     }
                     lastSendTimer = timeNow;
@@ -87,20 +86,20 @@ namespace ET.Client
                     int messageLength = socket.ReceiveFrom(recvCache, ref recvIPEndPoint);
                     if (messageLength != 9)
                     {
-                        Log.Error($"router connect error1: {connectId} {messageLength} {localConn} {remoteConn} {routerAddress} {realAddress}");
+                        fiber.Error($"router connect error1: {connectId} {messageLength} {localConn} {remoteConn} {routerAddress} {realAddress}");
                         continue;
                     }
 
                     byte flag = recvCache[0];
                     if (flag != KcpProtocalType.RouterReconnectACK && flag != KcpProtocalType.RouterACK)
                     {
-                        Log.Error($"router connect error2: {connectId} {synFlag} {flag} {localConn} {remoteConn} {routerAddress} {realAddress}");
+                        fiber.Error($"router connect error2: {connectId} {synFlag} {flag} {localConn} {remoteConn} {routerAddress} {realAddress}");
                         continue;
                     }
 
                     uint recvRemoteConn = BitConverter.ToUInt32(recvCache, 1);
                     uint recvLocalConn = BitConverter.ToUInt32(recvCache, 5);
-                    Log.Info($"router connect finish: {connectId} {recvRemoteConn} {recvLocalConn} {localConn} {remoteConn} {routerAddress} {realAddress}");
+                    fiber.Info($"router connect finish: {connectId} {recvRemoteConn} {recvLocalConn} {localConn} {remoteConn} {routerAddress} {realAddress}");
                     return recvLocalConn;
                 }
             }

+ 4 - 3
Unity/Assets/Scripts/Hotfix/Client/LockStep/LSClientHelper.cs

@@ -88,7 +88,8 @@ namespace ET.Client
             {
                 return;
             }
-            Log.Debug($"save replay: {path} frame: {room.Replay.FrameInputs.Count}");
+            
+            room.Fiber().Debug($"save replay: {path} frame: {room.Replay.FrameInputs.Count}");
             byte[] bytes = MemoryPackHelper.Serialize(room.Replay);
             File.WriteAllBytes(path, bytes);
         }
@@ -106,7 +107,7 @@ namespace ET.Client
             }
             
             int snapshotIndex = frame / LSConstValue.SaveLSWorldFrameCount;
-            Log.Debug($"jump replay start {room.AuthorityFrame} {frame} {snapshotIndex}");
+            room.Fiber().Debug($"jump replay start {room.AuthorityFrame} {frame} {snapshotIndex}");
             if (snapshotIndex != room.AuthorityFrame / LSConstValue.SaveLSWorldFrameCount || frame < room.AuthorityFrame)
             {
                 room.LSWorld.Dispose();
@@ -120,7 +121,7 @@ namespace ET.Client
             
             room.FixedTimeCounter.Reset(TimeInfo.Instance.ServerFrameTime() - frame * LSConstValue.UpdateInterval, 0);
 
-            Log.Debug($"jump replay finish {frame}");
+            room.Fiber().Debug($"jump replay finish {frame}");
         }
     }
 }

+ 5 - 5
Unity/Assets/Scripts/Hotfix/Client/LockStep/OneFrameInputsHandler.cs

@@ -8,10 +8,10 @@ namespace ET.Client
         protected override async ETTask Run(Scene root, OneFrameInputs input)
         {
             using var _ = input ; // 方法结束时回收消息
-            
+            Fiber fiber = root.Fiber();
             Room room = root.GetComponent<Room>();
             
-            Log.Debug($"OneFrameInputs: {room.AuthorityFrame + 1} {input.ToJson()}");
+            fiber.Debug($"OneFrameInputs: {room.AuthorityFrame + 1} {input.ToJson()}");
                         
             FrameBuffer frameBuffer = room.FrameBuffer;
 
@@ -32,12 +32,12 @@ namespace ET.Client
                 // 回滚重新预测的时候,自己的输入不用变化
                 if (input != predictionInput)
                 {
-                    Log.Debug($"frame diff: {predictionInput} {input}");
+                    fiber.Debug($"frame diff: {predictionInput} {input}");
                     input.CopyTo(predictionInput);
                     // 回滚到frameBuffer.AuthorityFrame
-                    Log.Debug($"roll back start {room.AuthorityFrame}");
+                    fiber.Debug($"roll back start {room.AuthorityFrame}");
                     LSClientHelper.Rollback(room, room.AuthorityFrame);
-                    Log.Debug($"roll back finish {room.AuthorityFrame}");
+                    fiber.Debug($"roll back finish {room.AuthorityFrame}");
                 }
                 else // 对比成功
                 {

+ 3 - 2
Unity/Assets/Scripts/Hotfix/Client/LockStep/Room2C_CheckHashFailHandler.cs

@@ -5,17 +5,18 @@ namespace ET.Client
     {
         protected override async ETTask Run(Scene root, Room2C_CheckHashFail message)
         {
+            Fiber fiber = root.Fiber();
             LSWorld serverWorld = MongoHelper.Deserialize(typeof(LSWorld), message.LSWorldBytes, 0, message.LSWorldBytes.Length) as LSWorld;
             using (root.AddChild(serverWorld))
             {
-                Log.Debug($"check hash fail, server: {message.Frame} {serverWorld.ToJson()}");
+                fiber.Debug($"check hash fail, server: {message.Frame} {serverWorld.ToJson()}");
             }
 
             Room room = root.GetComponent<Room>();
             LSWorld clientWorld = room.GetLSWorld(SceneType.LockStepClient, message.Frame);
             using (root.AddChild(clientWorld))
             {
-                Log.Debug($"check hash fail, client: {message.Frame} {clientWorld.ToJson()}");
+                fiber.Debug($"check hash fail, client: {message.Frame} {clientWorld.ToJson()}");
             }
             
             message.Dispose();

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs

@@ -12,7 +12,7 @@ namespace ET.Client
         [EntitySystem]
         private static void Awake(this NetClientComponent self, AddressFamily addressFamily)
         {
-            self.AService = new KService(addressFamily, ServiceType.Outer);
+            self.AService = new KService(addressFamily, ServiceType.Outer, self.Fiber().Log);
             self.AService.ReadCallback = self.OnRead;
             self.AService.ErrorCallback = self.OnError;
         }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Benchmark/C2G_BenchmarkHandler.cs

@@ -10,7 +10,7 @@ namespace ET.Server
             BenchmarkServerComponent benchmarkServerComponent = session.Scene().GetComponent<BenchmarkServerComponent>();
             if (benchmarkServerComponent.Count++ % 1000000 == 0)
             {
-                Log.Debug($"benchmark count: {benchmarkServerComponent.Count} {TimeInfo.Instance.ClientNow()}");
+                session.Fiber().Debug($"benchmark count: {benchmarkServerComponent.Count} {TimeInfo.Instance.ClientNow()}");
             }
             await ETTask.CompletedTask;
         }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Realm/C2R_LoginHandler.cs

@@ -11,7 +11,7 @@ namespace ET.Server
 		{
 			// 随机分配一个Gate
 			StartSceneConfig config = RealmGateAddressHelper.GetGate(session.Zone(), request.Account);
-			Log.Debug($"gate address: {config}");
+			session.Fiber().Debug($"gate address: {config}");
 			
 			// 向gate请求一个key,客户端可以拿着这个key连接gate
 			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey) await session.Fiber().Root.GetComponent<MessageSender>().Call(

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Robot/Console/CreateRobotConsoleHandler.cs

@@ -12,7 +12,7 @@ namespace ET.Server
             switch (content)
             {
                 case ConsoleMode.CreateRobot:
-                    Log.Console("CreateRobot args error!");
+                    fiber.Console("CreateRobot args error!");
                     break;
                 default:
                     CreateRobotArgs options = null;

+ 7 - 7
Unity/Assets/Scripts/Hotfix/Server/Demo/Robot/RobotConsoleHandler.cs

@@ -20,13 +20,13 @@ namespace ET.Server
 
                     try
                     {
-                        RobotLog.Debug($"run case start: {caseType}");
+                        fiber.Debug($"run case start: {caseType}");
                         await EventSystem.Instance.Invoke<RobotInvokeArgs, ETTask>(caseType, new RobotInvokeArgs() { Fiber = fiber, Content = content });
-                        RobotLog.Debug($"run case finish: {caseType}");
+                        fiber.Debug($"run case finish: {caseType}");
                     }
                     catch (Exception e)
                     {
-                        RobotLog.Debug($"run case error: {caseType}\n{e}");
+                        fiber.Debug($"run case error: {caseType}\n{e}");
                     }
                     break;
                 }
@@ -38,18 +38,18 @@ namespace ET.Server
                         int caseType = (int)fieldInfo.GetValue(null);
                         if (caseType > RobotCaseType.MaxCaseType)
                         {
-                            RobotLog.Debug($"case > {RobotCaseType.MaxCaseType}: {caseType}");
+                            fiber.Debug($"case > {RobotCaseType.MaxCaseType}: {caseType}");
                             break;
                         }
                         try
                         {
-                            RobotLog.Debug($"run case start: {caseType}");
+                            fiber.Debug($"run case start: {caseType}");
                             await EventSystem.Instance.Invoke<RobotInvokeArgs, ETTask>(caseType, new RobotInvokeArgs() { Fiber = fiber, Content = content});
-                            RobotLog.Debug($"---------run case finish: {caseType}");
+                            fiber.Debug($"---------run case finish: {caseType}");
                         }
                         catch (Exception e)
                         {
-                            RobotLog.Debug($"run case error: {caseType}\n{e}");
+                            fiber.Debug($"run case error: {caseType}\n{e}");
                             break;
                         }
                     }

+ 8 - 8
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationOneTypeSystem.cs

@@ -39,7 +39,7 @@ namespace ET.Server
             using (await self.Fiber().CoroutineLockComponent.Wait(coroutineLockType, key))
             {
                 self.locations[key] = instanceId;
-                Log.Info($"location add key: {key} instanceId: {instanceId}");
+                self.Fiber().Info($"location add key: {key} instanceId: {instanceId}");
             }
         }
 
@@ -49,7 +49,7 @@ namespace ET.Server
             using (await self.Fiber().CoroutineLockComponent.Wait(coroutineLockType, key))
             {
                 self.locations.Remove(key);
-                Log.Info($"location remove key: {key}");
+                self.Fiber().Info($"location remove key: {key}");
             }
         }
 
@@ -61,7 +61,7 @@ namespace ET.Server
             LockInfo lockInfo = self.AddChild<LockInfo, ActorId, CoroutineLock>(actorId, coroutineLock);
             self.lockInfos.Add(key, lockInfo);
 
-            Log.Info($"location lock key: {key} instanceId: {actorId}");
+            self.Fiber().Info($"location lock key: {key} instanceId: {actorId}");
 
             if (time > 0)
             {
@@ -73,7 +73,7 @@ namespace ET.Server
                     {
                         return;
                     }
-                    Log.Info($"location timeout unlock key: {key} instanceId: {actorId} newInstanceId: {actorId}");
+                    self.Fiber().Info($"location timeout unlock key: {key} instanceId: {actorId} newInstanceId: {actorId}");
                     self.UnLock(key, actorId, actorId);
                 }
                 TimeWaitAsync().Coroutine();
@@ -84,17 +84,17 @@ namespace ET.Server
         {
             if (!self.lockInfos.TryGetValue(key, out LockInfo lockInfo))
             {
-                Log.Error($"location unlock not found key: {key} {oldActorId}");
+                self.Fiber().Error($"location unlock not found key: {key} {oldActorId}");
                 return;
             }
 
             if (oldActorId != lockInfo.LockActorId)
             {
-                Log.Error($"location unlock oldInstanceId is different: {key} {oldActorId}");
+                self.Fiber().Error($"location unlock oldInstanceId is different: {key} {oldActorId}");
                 return;
             }
 
-            Log.Info($"location unlock key: {key} instanceId: {oldActorId} newInstanceId: {newInstanceId}");
+            self.Fiber().Info($"location unlock key: {key} instanceId: {oldActorId} newInstanceId: {newInstanceId}");
 
             self.locations[key] = newInstanceId;
 
@@ -110,7 +110,7 @@ namespace ET.Server
             using (await self.Fiber().CoroutineLockComponent.Wait(coroutineLockType, key))
             {
                 self.locations.TryGetValue(key, out ActorId actorId);
-                Log.Info($"location get key: {key} actorId: {actorId}");
+                self.Fiber().Info($"location get key: {key} actorId: {actorId}");
                 return actorId;
             }
         }

+ 12 - 8
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs

@@ -11,29 +11,33 @@ namespace ET.Server
 
         public static async ETTask Add(this LocationProxyComponent self, int type, long key, ActorId actorId)
         {
-            Log.Info($"location proxy add {key}, {actorId} {TimeInfo.Instance.ServerNow()}");
-            await self.Root().GetComponent<MessageSender>().Call(GetLocationSceneId(key),
+            Fiber fiber = self.Fiber();
+            fiber.Info($"location proxy add {key}, {actorId} {TimeInfo.Instance.ServerNow()}");
+            await fiber.Root.GetComponent<MessageSender>().Call(GetLocationSceneId(key),
                 new ObjectAddRequest() { Type = type, Key = key, ActorId = actorId });
         }
 
         public static async ETTask Lock(this LocationProxyComponent self, int type, long key, ActorId actorId, int time = 60000)
         {
-            Log.Info($"location proxy lock {key}, {actorId} {TimeInfo.Instance.ServerNow()}");
-            await self.Root().GetComponent<MessageSender>().Call(GetLocationSceneId(key),
+            Fiber fiber = self.Fiber();
+            fiber.Info($"location proxy lock {key}, {actorId} {TimeInfo.Instance.ServerNow()}");
+            await fiber.Root.GetComponent<MessageSender>().Call(GetLocationSceneId(key),
                 new ObjectLockRequest() { Type = type, Key = key, ActorId = actorId, Time = time });
         }
 
         public static async ETTask UnLock(this LocationProxyComponent self, int type, long key, ActorId oldActorId, ActorId newActorId)
         {
-            Log.Info($"location proxy unlock {key}, {newActorId} {TimeInfo.Instance.ServerNow()}");
-            await self.Root().GetComponent<MessageSender>().Call(GetLocationSceneId(key),
+            Fiber fiber = self.Fiber();
+            fiber.Info($"location proxy unlock {key}, {newActorId} {TimeInfo.Instance.ServerNow()}");
+            await fiber.Root.GetComponent<MessageSender>().Call(GetLocationSceneId(key),
                 new ObjectUnLockRequest() { Type = type, Key = key, OldActorId = oldActorId, NewActorId = newActorId });
         }
 
         public static async ETTask Remove(this LocationProxyComponent self, int type, long key)
         {
-            Log.Info($"location proxy add {key}, {TimeInfo.Instance.ServerNow()}");
-            await self.Root().GetComponent<MessageSender>().Call(GetLocationSceneId(key),
+            Fiber fiber = self.Fiber();
+            fiber.Info($"location proxy add {key}, {TimeInfo.Instance.ServerNow()}");
+            await fiber.Root.GetComponent<MessageSender>().Call(GetLocationSceneId(key),
                 new ObjectRemoveRequest() { Type = type, Key = key });
         }
 

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/MessageLocationSenderComponentSystem.cs

@@ -257,7 +257,7 @@ namespace ET.Server
                         ++failTimes;
                         if (failTimes > 20)
                         {
-                            Log.Debug($"actor send message fail, actorid: {messageLocationSender.Id} {iRequest}");
+                            root.Fiber().Debug($"actor send message fail, actorid: {messageLocationSender.Id} {iRequest}");
                             messageLocationSender.Error = ErrorCore.ERR_NotFoundActor;
                             // 这里不能删除actor,要让后面等待发送的消息也返回ERR_NotFoundActor,直到超时删除
                             return response;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/MessageLocationSenderSystem.cs

@@ -17,7 +17,7 @@ namespace ET.Server
         [EntitySystem]
         private static void Destroy(this MessageLocationSender self)
         {
-            Log.Debug($"actor location remove: {self.Id}");
+            self.Fiber().Debug($"actor location remove: {self.Id}");
             self.LastSendOrRecvTime = 0;
             self.ActorId = default;
             self.Error = 0;

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/Message/MessageOuterSenderSystem.cs

@@ -14,12 +14,12 @@ namespace ET.Server
             {
                 case NetworkProtocol.TCP:
                 {
-                    self.AService = new TService(address, ServiceType.Inner);
+                    self.AService = new TService(address, ServiceType.Inner, self.Fiber().Log);
                     break;
                 }
                 case NetworkProtocol.KCP:
                 {
-                    self.AService = new KService(address, ServiceType.Inner);
+                    self.AService = new KService(address, ServiceType.Inner, self.Fiber().Log);
                     break;
                 }
             }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs

@@ -10,7 +10,7 @@ namespace ET.Server
         [EntitySystem]
         private static void Awake(this NetServerComponent self, IPEndPoint address)
         {
-            self.AService = new KService(address, ServiceType.Outer);
+            self.AService = new KService(address, ServiceType.Outer, self.Fiber().Log);
             self.AService.AcceptCallback = self.OnAccept;
             self.AService.ReadCallback = self.OnRead;
             self.AService.ErrorCallback = self.OnError;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/RobotCase/ARobotCase.cs

@@ -17,7 +17,7 @@ namespace ET.Server
             catch (System.Exception e)
             {
                 Log.Error($"{robotCase.Zone()} {e}");
-                RobotLog.Console($"RobotCase Error {this.GetType().FullName}:\n\t{e}");
+                robotCase.Fiber().Console($"RobotCase Error {this.GetType().FullName}:\n\t{e}");
             }
         }
     }

+ 34 - 33
Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs

@@ -147,6 +147,7 @@ namespace ET.Server
                 return;
             }
 
+            Fiber fiber = self.Fiber();
             // accept
             byte flag = self.Cache[0];
             switch (flag)
@@ -171,7 +172,7 @@ namespace ET.Server
                         self.ConnectIdNodes.TryGetValue(connectId, out routerNode);
                         if (routerNode == null)
                         {
-                            Log.Info($"router create reconnect: {self.IPEndPoint} {realAddress} {connectId} {outerConn} {innerConn}");
+                            fiber.Info($"router create reconnect: {self.IPEndPoint} {realAddress} {connectId} {outerConn} {innerConn}");
                             routerNode = self.New(realAddress, connectId, outerConn, innerConn, self.CloneAddress());
                             // self.OuterNodes 这里不能add,因为还没验证完成,要在RouterAck中加入
                         }
@@ -179,7 +180,7 @@ namespace ET.Server
 
                     if (routerNode.ConnectId != connectId)
                     {
-                        Log.Warning($"kcp router router reconnect connectId diff1: {routerNode.SyncIpEndPoint} {(IPEndPoint) self.IPEndPoint}");
+                        fiber.Warning($"kcp router router reconnect connectId diff1: {routerNode.SyncIpEndPoint} {(IPEndPoint) self.IPEndPoint}");
                         break;
                     }
                     
@@ -187,27 +188,27 @@ namespace ET.Server
                     // 这个路由连接不上,客户端会换个软路由,所以没关系
                     if (routerNode.InnerConn != innerConn)
                     {
-                        Log.Warning($"kcp router router reconnect inner conn diff1: {routerNode.SyncIpEndPoint} {(IPEndPoint) self.IPEndPoint}");
+                        fiber.Warning($"kcp router router reconnect inner conn diff1: {routerNode.SyncIpEndPoint} {(IPEndPoint) self.IPEndPoint}");
                         break;
                     }
                     
                     if (routerNode.OuterConn != outerConn)
                     {
-                        Log.Warning($"kcp router router reconnect outer conn diff1: {routerNode.SyncIpEndPoint} {(IPEndPoint) self.IPEndPoint}");
+                        fiber.Warning($"kcp router router reconnect outer conn diff1: {routerNode.SyncIpEndPoint} {(IPEndPoint) self.IPEndPoint}");
                         break;
                     }
 
                     // 校验ip,连接过程中ip不能变化
                     if (!Equals(routerNode.SyncIpEndPoint, self.IPEndPoint))
                     {
-                        Log.Warning($"kcp router syn ip is diff1: {routerNode.SyncIpEndPoint} {(IPEndPoint) self.IPEndPoint}");
+                        fiber.Warning($"kcp router syn ip is diff1: {routerNode.SyncIpEndPoint} {(IPEndPoint) self.IPEndPoint}");
                         break;
                     }
 
                     // 校验内网地址
                     if (routerNode.InnerAddress != realAddress)
                     {
-                        Log.Warning($"router sync error2: {routerNode.OuterConn} {routerNode.InnerAddress} {outerConn} {realAddress}");
+                        fiber.Warning($"router sync error2: {routerNode.OuterConn} {routerNode.InnerAddress} {outerConn} {realAddress}");
                         break;
                     }
                     
@@ -250,7 +251,7 @@ namespace ET.Server
                     {
                         outerConn = NetServices.Instance.CreateConnectChannelId();
                         routerNode = self.New(realAddress, connectId, outerConn, innerConn, self.CloneAddress());
-                        Log.Info($"router create: {realAddress} {connectId} {outerConn} {innerConn} {routerNode.SyncIpEndPoint}");
+                        fiber.Info($"router create: {realAddress} {connectId} {outerConn} {innerConn} {routerNode.SyncIpEndPoint}");
                         self.OuterNodes.Add(routerNode.OuterConn, routerNode);
                     }
 
@@ -263,14 +264,14 @@ namespace ET.Server
                     // 校验ip,连接过程中ip不能变化
                     if (!Equals(routerNode.SyncIpEndPoint, self.IPEndPoint))
                     {
-                        Log.Warning($"kcp router syn ip is diff1: {routerNode.SyncIpEndPoint} {self.IPEndPoint}");
+                        fiber.Warning($"kcp router syn ip is diff1: {routerNode.SyncIpEndPoint} {self.IPEndPoint}");
                         break;
                     }
 
                     // 校验内网地址
                     if (routerNode.InnerAddress != realAddress)
                     {
-                        Log.Warning($"router sync error2: {routerNode.OuterConn} {routerNode.InnerAddress} {outerConn} {realAddress}");
+                        fiber.Warning($"router sync error2: {routerNode.OuterConn} {routerNode.InnerAddress} {outerConn} {realAddress}");
                         break;
                     }
 
@@ -299,7 +300,7 @@ namespace ET.Server
 
                     if (!self.OuterNodes.TryGetValue(outerConn, out RouterNode kcpRouter))
                     {
-                        Log.Warning($"kcp router syn not found outer nodes: {outerConn} {innerConn}");
+                        fiber.Warning($"kcp router syn not found outer nodes: {outerConn} {innerConn}");
                         break;
                     }
 
@@ -313,7 +314,7 @@ namespace ET.Server
                     IPEndPoint ipEndPoint = (IPEndPoint) self.IPEndPoint;
                     if (!Equals(kcpRouter.SyncIpEndPoint.Address, ipEndPoint.Address))
                     {
-                        Log.Warning($"kcp router syn ip is diff3: {kcpRouter.SyncIpEndPoint.Address} {ipEndPoint.Address}");
+                        fiber.Warning($"kcp router syn ip is diff3: {kcpRouter.SyncIpEndPoint.Address} {ipEndPoint.Address}");
                         break;
                     }
                     
@@ -328,7 +329,7 @@ namespace ET.Server
                     self.Cache.WriteTo(5, innerConn);
                     byte[] addressBytes = ipEndPoint.ToString().ToByteArray();
                     Array.Copy(addressBytes, 0, self.Cache, 9, addressBytes.Length);
-                    Log.Info($"kcp router syn: {outerConn} {innerConn} {kcpRouter.InnerIpEndPoint} {kcpRouter.OuterIpEndPoint}");
+                    fiber.Info($"kcp router syn: {outerConn} {innerConn} {kcpRouter.InnerIpEndPoint} {kcpRouter.OuterIpEndPoint}");
                     self.InnerSocket.SendTo(self.Cache, 0, 9 + addressBytes.Length, SocketFlags.None, kcpRouter.InnerIpEndPoint);
 
                     if (!kcpRouter.CheckOuterCount(timeNow))
@@ -351,19 +352,19 @@ namespace ET.Server
 
                     if (!self.OuterNodes.TryGetValue(outerConn, out RouterNode kcpRouter))
                     {
-                        Log.Warning($"kcp router outer fin not found outer nodes: {outerConn} {innerConn}");
+                        fiber.Warning($"kcp router outer fin not found outer nodes: {outerConn} {innerConn}");
                         break;
                     }
 
                     // 比对innerConn
                     if (kcpRouter.InnerConn != innerConn)
                     {
-                        Log.Warning($"router node innerConn error: {innerConn} {outerConn} {kcpRouter.Status}");
+                        fiber.Warning($"router node innerConn error: {innerConn} {outerConn} {kcpRouter.Status}");
                         break;
                     }
 
                     kcpRouter.LastRecvOuterTime = timeNow;
-                    Log.Info($"kcp router outer fin: {outerConn} {innerConn} {kcpRouter.InnerIpEndPoint}");
+                    fiber.Info($"kcp router outer fin: {outerConn} {innerConn} {kcpRouter.InnerIpEndPoint}");
                     self.InnerSocket.SendTo(self.Cache, 0, messageLength, SocketFlags.None, kcpRouter.InnerIpEndPoint);
 
                     if (!kcpRouter.CheckOuterCount(timeNow))
@@ -387,20 +388,20 @@ namespace ET.Server
 
                     if (!self.OuterNodes.TryGetValue(outerConn, out RouterNode kcpRouter))
                     {
-                        Log.Warning($"kcp router msg not found outer nodes: {outerConn} {innerConn}");
+                        fiber.Warning($"kcp router msg not found outer nodes: {outerConn} {innerConn}");
                         break;
                     }
 
                     if (kcpRouter.Status != RouterStatus.Msg)
                     {
-                        Log.Warning($"router node status error: {innerConn} {outerConn} {kcpRouter.Status}");
+                        fiber.Warning($"router node status error: {innerConn} {outerConn} {kcpRouter.Status}");
                         break;
                     }
 
                     // 比对innerConn
                     if (kcpRouter.InnerConn != innerConn)
                     {
-                        Log.Warning($"router node innerConn error: {innerConn} {outerConn} {kcpRouter.Status}");
+                        fiber.Warning($"router node innerConn error: {innerConn} {outerConn} {kcpRouter.Status}");
                         break;
                     }
 
@@ -434,7 +435,7 @@ namespace ET.Server
 
             // accept
             byte flag = self.Cache[0];
-
+            Fiber fiber = self.Fiber();
             switch (flag)
             {
                 case KcpProtocalType.RouterReconnectACK:
@@ -444,14 +445,14 @@ namespace ET.Server
                     uint connectId = BitConverter.ToUInt32(self.Cache, 9);
                     if (!self.ConnectIdNodes.TryGetValue(connectId, out RouterNode kcpRouterNode))
                     {
-                        Log.Warning($"router node error: {innerConn} {connectId}");
+                        fiber.Warning($"router node error: {innerConn} {connectId}");
                         break;
                     }
 
                     // 必须校验innerConn,防止伪造
                     if (innerConn != kcpRouterNode.InnerConn)
                     {
-                        Log.Warning(
+                        fiber.Warning(
                             $"router node innerConn error: {innerConn} {kcpRouterNode.InnerConn} {outerConn} {kcpRouterNode.OuterConn} {kcpRouterNode.Status}");
                         break;
                     }
@@ -459,7 +460,7 @@ namespace ET.Server
                     // 必须校验outerConn,防止伪造
                     if (outerConn != kcpRouterNode.OuterConn)
                     {
-                        Log.Warning(
+                        fiber.Warning(
                             $"router node outerConn error: {innerConn} {kcpRouterNode.InnerConn} {outerConn} {kcpRouterNode.OuterConn} {kcpRouterNode.Status}");
                         break;
                     }
@@ -479,7 +480,7 @@ namespace ET.Server
                     self.Cache.WriteTo(0, KcpProtocalType.RouterReconnectACK);
                     self.Cache.WriteTo(1, kcpRouterNode.InnerConn);
                     self.Cache.WriteTo(5, kcpRouterNode.OuterConn);
-                    Log.Info($"kcp router RouterAck: {outerConn} {innerConn} {kcpRouterNode.SyncIpEndPoint}");
+                    fiber.Info($"kcp router RouterAck: {outerConn} {innerConn} {kcpRouterNode.SyncIpEndPoint}");
                     self.OuterSocket.SendTo(self.Cache, 0, 9, SocketFlags.None, kcpRouterNode.SyncIpEndPoint);
                     break;
                 }
@@ -491,7 +492,7 @@ namespace ET.Server
 
                     if (!self.OuterNodes.TryGetValue(outerConn, out RouterNode kcpRouterNode))
                     {
-                        Log.Warning($"kcp router ack not found outer nodes: {outerConn} {innerConn}");
+                        fiber.Warning($"kcp router ack not found outer nodes: {outerConn} {innerConn}");
                         break;
                     }
                     
@@ -501,7 +502,7 @@ namespace ET.Server
 
                     kcpRouterNode.LastRecvInnerTime = timeNow;
                     // 转发出去
-                    Log.Info($"kcp router ack: {outerConn} {innerConn} {kcpRouterNode.OuterIpEndPoint}");
+                    fiber.Info($"kcp router ack: {outerConn} {innerConn} {kcpRouterNode.OuterIpEndPoint}");
                     self.OuterSocket.SendTo(self.Cache, 0, messageLength, SocketFlags.None, kcpRouterNode.OuterIpEndPoint);
                     break;
                 }
@@ -518,14 +519,14 @@ namespace ET.Server
 
                     if (!self.OuterNodes.TryGetValue(outerConn, out RouterNode kcpRouterNode))
                     {
-                        Log.Warning($"kcp router inner fin not found outer nodes: {outerConn} {innerConn}");
+                        fiber.Warning($"kcp router inner fin not found outer nodes: {outerConn} {innerConn}");
                         break;
                     }
 
                     // 比对innerConn
                     if (kcpRouterNode.InnerConn != innerConn)
                     {
-                        Log.Warning($"router node innerConn error: {innerConn} {outerConn} {kcpRouterNode.Status}");
+                        fiber.Warning($"router node innerConn error: {innerConn} {outerConn} {kcpRouterNode.Status}");
                         break;
                     }
 
@@ -536,7 +537,7 @@ namespace ET.Server
                     }
 
                     kcpRouterNode.LastRecvInnerTime = timeNow;
-                    Log.Info($"kcp router inner fin: {outerConn} {innerConn} {kcpRouterNode.OuterIpEndPoint}");
+                    fiber.Info($"kcp router inner fin: {outerConn} {innerConn} {kcpRouterNode.OuterIpEndPoint}");
                     self.OuterSocket.SendTo(self.Cache, 0, messageLength, SocketFlags.None, kcpRouterNode.OuterIpEndPoint);
 
                     break;
@@ -555,14 +556,14 @@ namespace ET.Server
 
                     if (!self.OuterNodes.TryGetValue(outerConn, out RouterNode kcpRouterNode))
                     {
-                        Log.Warning($"kcp router inner msg not found outer nodes: {outerConn} {innerConn}");
+                        fiber.Warning($"kcp router inner msg not found outer nodes: {outerConn} {innerConn}");
                         break;
                     }
 
                     // 比对innerConn
                     if (kcpRouterNode.InnerConn != innerConn)
                     {
-                        Log.Warning($"router node innerConn error: {innerConn} {outerConn} {kcpRouterNode.Status}");
+                        fiber.Warning($"router node innerConn error: {innerConn} {outerConn} {kcpRouterNode.Status}");
                         break;
                     }
 
@@ -602,7 +603,7 @@ namespace ET.Server
 
             routerNode.Status = RouterStatus.Sync;
 
-            Log.Info($"router new: outerConn: {outerConn} innerConn: {innerConn} {syncEndPoint}");
+            self.Fiber().Info($"router new: outerConn: {outerConn} innerConn: {innerConn} {syncEndPoint}");
 
             return routerNode;
         }
@@ -615,7 +616,7 @@ namespace ET.Server
                 return;
             }
 
-            Log.Info($"router node remove: {routerNode.OuterConn} {routerNode.InnerConn} {error}");
+            self.Fiber().Info($"router node remove: {routerNode.OuterConn} {routerNode.InnerConn} {error}");
             self.Remove(id);
         }
 
@@ -638,7 +639,7 @@ namespace ET.Server
                 }
             }
 
-            Log.Info($"router remove: {routerNode.Id} outerConn: {routerNode.OuterConn} innerConn: {routerNode.InnerConn}");
+            self.Fiber().Info($"router remove: {routerNode.Id} outerConn: {routerNode.OuterConn} innerConn: {routerNode.InnerConn}");
 
             routerNode.Dispose();
         }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionIdleCheckerComponentSystem.cs

@@ -46,7 +46,7 @@ namespace ET
                 return;
             }
 
-            Log.Info($"session timeout: {session.Id} {timeNow} {session.LastRecvTime} {session.LastSendTime} {timeNow - session.LastRecvTime} {timeNow - session.LastSendTime}");
+            self.Fiber().Info($"session timeout: {session.Id} {timeNow} {session.LastRecvTime} {session.LastSendTime} {timeNow - session.LastRecvTime} {timeNow - session.LastSendTime}");
             session.Error = ErrorCore.ERR_SessionSendOrRecvTimeout;
 
             session.Dispose();

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Recast/PathfindingComponentSystem.cs

@@ -34,7 +34,7 @@ namespace ET
         {
             if (self.navMesh == IntPtr.Zero)
             {
-                Log.Debug("寻路| Find 失败 pathfinding ptr is zero");
+                self.Fiber().Debug("寻路| Find 失败 pathfinding ptr is zero");
                 throw new Exception($"pathfinding ptr is zero: {self.Scene().Name}");
             }
 

+ 3 - 2
Unity/Assets/Scripts/HotfixView/Client/Demo/UI/UILobby/UILobbyComponentSystem.cs

@@ -18,8 +18,9 @@ namespace ET.Client
         
         public static async ETTask EnterMap(this UILobbyComponent self)
         {
-            await EnterMapHelper.EnterMapAsync(self.Root());
-            await UIHelper.Remove(self.Root(), UIType.UILobby);
+            Scene root = self.Root();
+            await EnterMapHelper.EnterMapAsync(root);
+            await UIHelper.Remove(root, UIType.UILobby);
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/HotfixView/Client/LockStep/UI/UILSLobby/UILSLobbyComponentSystem.cs

@@ -34,7 +34,7 @@ namespace ET.Client
             byte[] bytes = File.ReadAllBytes(self.replayPath.text);
             
             Replay replay = MemoryPackHelper.Deserialize(typeof (Replay), bytes, 0, bytes.Length) as Replay;
-            Log.Debug($"start replay: {replay.Snapshots.Count} {replay.FrameInputs.Count} {replay.UnitInfos.Count}");
+            self.Fiber().Debug($"start replay: {replay.Snapshots.Count} {replay.FrameInputs.Count} {replay.UnitInfos.Count}");
             LSSceneChangeHelper.SceneChangeToReplay(self.Root(), replay).Coroutine();
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs

@@ -23,7 +23,7 @@ namespace ET
 				.WithParsed((o)=>World.Instance.AddSingleton(o));
 			Options.Instance.StartConfig = $"StartConfig/Localhost";
 			
-			World.Instance.AddSingleton<Logger>().ILog = new UnityLogger();
+			World.Instance.AddSingleton<Logger>().Log = new UnityLogger();
 			ETTask.ExceptionHandler += Log.Error;
 			
 			World.Instance.AddSingleton<CodeLoader>().Start();

+ 0 - 27
Unity/Assets/Scripts/Model/Server/Module/RobotCase/RobotLog.cs

@@ -1,27 +0,0 @@
-namespace ET.Server
-{
-	public static class RobotLog
-	{
-#if DOTNET
-		public static void Debug(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
-		{
-			Logger.Instance.Debug(message.ToStringAndClear());
-		}
-		
-		public static void Console(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
-		{
-			Logger.Instance.Console(message.ToStringAndClear());
-		}
-#endif
-		
-		public static void Debug(string msg)
-		{
-			Logger.Instance.Debug(msg);
-		}
-
-		public static void Console(string msg)
-		{
-			Logger.Instance.Console(msg);
-		}
-	}
-}

+ 1 - 1
Unity/Assets/Scripts/Model/Share/LockStep/LSWorld.cs

@@ -38,7 +38,7 @@ namespace ET
 
             this.SceneType = sceneType;
             
-            Log.Info($"LSScene create: {this.Id} {this.InstanceId}");
+            this.Fiber().Info($"LSScene create: {this.Id} {this.InstanceId}");
         }
 
         private readonly LSUpdater updater = new();

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Message/LogMsg.cs

@@ -23,7 +23,7 @@ namespace ET
             {
                 return;
             }
-            Logger.Instance.Debug(msg.ToString());
+            Logger.Instance.Log.Debug(msg.ToString());
         }
     }
 }

+ 2 - 2
Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs

@@ -31,7 +31,7 @@ namespace ET
 
             self.requestCallbacks.Clear();
             
-            Log.Info($"session create: zone: {self.Zone()} id: {self.Id} {timeNow} ");
+            self.Fiber().Info($"session create: zone: {self.Zone()} id: {self.Id} {timeNow} ");
         }
         
         [EntitySystem]
@@ -44,7 +44,7 @@ namespace ET
                 responseCallback.Tcs.SetException(new RpcException(self.Error, $"session dispose: {self.Id} {self.RemoteAddress}"));
             }
 
-            Log.Info($"session dispose: {self.RemoteAddress} id: {self.Id} ErrorCode: {self.Error}, please see ErrorCode.cs! {TimeInfo.Instance.ClientNow()}");
+            self.Fiber().Info($"session dispose: {self.RemoteAddress} id: {self.Id} ErrorCode: {self.Error}, please see ErrorCode.cs! {TimeInfo.Instance.ClientNow()}");
             
             self.requestCallbacks.Clear();
         }

+ 2 - 2
Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesComponent.cs

@@ -478,7 +478,7 @@ namespace ET.Client
                     }
                     else
                     {
-                        Log.Error("Bundle not exist! BundleName: " + assetBundleName);
+                        self.Fiber().Error("Bundle not exist! BundleName: " + assetBundleName);
                     }
 
                     // 编辑器模式也不能同步加载
@@ -494,7 +494,7 @@ namespace ET.Client
                 p = Path.Combine(PathHelper.AppResPath, assetBundleName);
             }
 
-            Log.Debug("Async load bundle BundleName : " + p);
+            self.Fiber().Debug("Async load bundle BundleName : " + p);
 
             // if (!File.Exists(p))
             // {