From 5e851678cc02257bbbd179446de36082430ca5bc Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 13 四月 2026 15:12:04 +0800
Subject: [PATCH] feat(MES): 添加Mes_Log扩展逻辑
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs | 34 +++++++++++++++++++++++++++++-----
1 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
index cf44abb..a3e0f16 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,9 +43,27 @@
loggerConfiguration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
- .Enrich.FromLogContext()
- .WriteTo.Console()
- .WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day);
+ //.Enrich.FromLogContext()
+ .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
+ .WriteTo.File(
+ //new JsonFormatter(renderMessage: true),
+ "logs/serilog-.log",
+ outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
+ rollingInterval: RollingInterval.Day,
+ retainedFileCountLimit: 30,
+ // 姣忎釜鏃ュ織鏂囦欢鏈�澶уぇ灏忥紙瀛楄妭锛夛紝姝ゅ璁剧疆涓�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();
@@ -62,6 +81,7 @@
builder.Services.AddDbSetup(); // Db 鏁版嵁搴撻厤缃�
builder.Services.AddInitializationHostServiceSetup(); // 搴旂敤绋嬪簭鍒濆鍖栨湇鍔℃敞鍐�
builder.Services.AddHostedService<AutoOutboundTaskBackgroundService>(); // 鍚姩鑷姩鍑哄簱浠诲姟鍚庡彴鏈嶅姟
+builder.Services.AddHostedService<StockMonitorBackgroundService>(); // 鍚姩搴撳瓨鐩戞帶鍚庡彴鏈嶅姟
// builder.Services.AddHostedService<PermissionDataHostService>(); // 鏉冮檺鏁版嵁鏈嶅姟
builder.Services.AddAutoMapperSetup();
@@ -79,6 +99,8 @@
options.Filters.Add(typeof(ApiAuthorizeFilter));
options.Filters.Add(typeof(ActionExecuteFilter));
});
+
+builder.Services.AddSignalR();
builder.Services.AddScoped<HttpClientHelper>();
@@ -155,4 +177,6 @@
app.MapControllers();
+app.MapHub<WIDESEA_WMSServer.Hubs.StockHub>("/stockHub");
+
app.Run();
--
Gitblit v1.9.3