From e25dc0d8fad5a2362bf75cf5ca9f26a0fe6c674c Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 26 三月 2026 11:28:15 +0800
Subject: [PATCH] feat(WMS): 增强日志配置与添加事务处理支持

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
index 8ea1382..e5332e1 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
@@ -1,5 +1,3 @@
-using System.Reflection;
-using System.Text;
 using Autofac;
 using Autofac.Core;
 using Autofac.Extensions.DependencyInjection;
@@ -12,6 +10,9 @@
 using Newtonsoft.Json.Converters;
 using Newtonsoft.Json.Serialization;
 using Serilog;
+using Serilog.Formatting.Json;
+using System.Reflection;
+using System.Text;
 using WIDESEA_Core;
 using WIDESEA_Core.Authorization;
 using WIDESEA_Core.BaseServices;
@@ -42,13 +43,27 @@
     loggerConfiguration
         .ReadFrom.Configuration(context.Configuration)
         .ReadFrom.Services(services)
-        .Enrich.FromLogContext()
-        .WriteTo.Console()
+        //.Enrich.FromLogContext()
+        .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
         .WriteTo.File(
-            "logs/serilog-.log.txt", 
+            //new JsonFormatter(renderMessage: true),
+            "logs/serilog-.log",
+            outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
             rollingInterval: RollingInterval.Day,
             retainedFileCountLimit: 30,
-            shared: true);
+            // 姣忎釜鏃ュ織鏂囦欢鏈�澶уぇ灏忥紙瀛楄妭锛夛紝姝ゅ璁剧疆涓�10MB
+            fileSizeLimitBytes: 10 * 1024 * 1024,
+            shared: true
+            )
+         // 6. 鍙�夛細杈撳嚭鍒癝eq鏃ュ織鏈嶅姟鍣紙缁撴瀯鍖栨棩蹇楁湇鍔″櫒锛�
+         // 闇�瑕佸畨瑁� Serilog.Sinks.Seq NuGet鍖咃紝骞剁‘淇漇eq鏈嶅姟鍦� http://localhost:5341 杩愯
+         // 濡備笉闇�瑕丼eq鏃ュ織锛屾敞閲婃帀涓嬫柟浠g爜鍗冲彲
+         .WriteTo.Seq(
+             serverUrl: "http://localhost:5341",
+             apiKey: "CWVa8UWQ9CdUp9GWXCPL", // 濡係eq闇�瑕丄piKey鍒欓厤缃湡瀹炲瘑閽�
+             batchPostingLimit: 1000, // 鎵归噺鍙戦�佹暟閲�
+             period: TimeSpan.FromSeconds(2) // 鍙戦�侀棿闅�
+         );
 });
 builder.ConfigureApplication();
 

--
Gitblit v1.9.3