林豪 左 2 年之前
父節點
當前提交
6ad83ff92a
共有 3 個文件被更改,包括 25 次插入7 次删除
  1. 20 0
      ServiceCenter/LogHub.cs
  2. 1 2
      ServiceCenter/WebApi/APICaller.cs
  3. 4 5
      WCS.WorkEngineering/worlds/MainWorld.cs

+ 20 - 0
ServiceCenter/LogHub.cs

@@ -0,0 +1,20 @@
+using WCS.Core;
+
+namespace ServiceCenter
+{
+    public class LogHub
+    {
+
+        /// <summary>
+        ///  发布一条日志记录
+        /// </summary>
+        /// <param name="path">路径</param>
+        /// <param name="title">文件名</param>
+        /// <param name="con">内容</param>
+        public static void Publish(string path, string title, string con)
+        {
+            if (!Directory.Exists(path)) Directory.CreateDirectory(path);
+            File.AppendAllText(Path.Combine(path, title), con);
+        }
+    }
+}

+ 1 - 2
ServiceCenter/WebApi/APICaller.cs

@@ -96,8 +96,7 @@ namespace ServiceCenter.WebApi
             {
                 var res = reader.ReadToEnd();
                 sw.Stop();
-                //if (sw.ElapsedMilliseconds > 500) Ltc.Log($"接口{url}调用耗时{sw.ElapsedMilliseconds}---------{JsonConvert.SerializeObject(res)}", LogLevel.Low, ErrorType.Kown);
-
+                LogHub.Publish($"D:\\WCSLogs\\{DateTime.Now.ToString("yyyy-MM-dd")}\\", $"接口调用日志.txt", $"接口{url}调用耗时{sw.ElapsedMilliseconds}---------{JsonConvert.SerializeObject(res)}/n");
                 return res;
             }
         }

+ 4 - 5
WCS.WorkEngineering/worlds/MainWorld.cs

@@ -1,4 +1,5 @@
-using System.Collections.Concurrent;
+using ServiceCenter;
+using System.Collections.Concurrent;
 using System.ComponentModel;
 using WCS.Core;
 using WCS.WorkEngineering.Worlds.Logs;
@@ -57,11 +58,9 @@ namespace WCS.WorkEngineering.Worlds
                 var time = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:FF")}";
                 foreach (var log in Logs)
                 {
-                    var dir = $"Logs\\{DateTime.Now.ToString("yyyy-MM-dd")}\\{log.Channel.World}\\{log.Channel.System}\\{log.Channel.Item}\\";
-                    if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
-
+                    var dir = $"D:\\WCSLogs\\{DateTime.Now.ToString("yyyy-MM-dd")}\\{log.Channel.World}\\{log.Channel.System}\\{log.Channel.Item}\\";
                     var msg = $"{log.Time}--[{Thread.CurrentThread.ManagedThreadId}]--{log}\n";
-                    File.AppendAllText(Path.Combine(dir, $"{log.Log.Message.Split(":")[0]}.txt"), msg);
+                    LogHub.Publish(dir, $"{log.Log.Message.Split(":")[0]}.txt", msg);
                 }
             }