From fe596f9db05103917c9257348edcbd3ecb5b46e8 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期四, 16 四月 2026 19:12:38 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/RuiShengZhiNeng/GaoPuLiTiKu
---
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs | 33 ++++++++++++++++++++++++++++++++-
1 files changed, 32 insertions(+), 1 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs"
index 75d3af8..8dfbad9 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs"
@@ -18,6 +18,7 @@
using WIDESEAWCS_Core.Extensions;
using WIDESEAWCS_Core.Filter;
using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_Core.Middlewares;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.QuartzExtensions;
@@ -50,6 +51,25 @@
builder.Services.AddHostedService<SeedDataHostedService>();//初始化数据库
builder.Services.AddDbSetup();//Db 启动服务
+
+#region 添加日志清理服务
+var cleanupRetentionDays = builder.Configuration.GetValue<int>("LogCleanup:RetentionDays", 90);
+var cleanupHour = builder.Configuration.GetValue<int>("LogCleanup:CleanupHour", 2);
+var enableAutoCleanup = builder.Configuration.GetValue<bool>("LogCleanup:EnableAutoCleanup", true);
+var enableArchive = builder.Configuration.GetValue<bool>("LogCleanup:EnableArchive", false);
+var logRetentionDays = builder.Configuration.GetValue<int>("LogCleanup:LogRetentionDays", 30);
+
+builder.Services.AddSingleton(sp => new LogCleanupService
+{
+ RetentionDays = cleanupRetentionDays,
+ CleanupHour = cleanupHour,
+ EnableAutoCleanup = enableAutoCleanup,
+ EnableArchive = enableArchive,
+ LogRetentionDays= logRetentionDays,
+ CleanupIntervalHours = 24
+});
+builder.Services.AddHostedService(sp => sp.GetRequiredService<LogCleanupService>());
+#endregion
//builder.Services.AddScoped<QuartzJobCreateDataTabel>();//任务调度 注入创建QuartzJob数据库表类
//builder.Services.AddHostedService<QuartzJobDataTableHostedService>();//任务调度 映射QuartzJob数据库表
@@ -123,7 +143,8 @@
app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("WIDESEAWCS_Server.index.html") ?? throw new Exception("未找到WIDESEAWCS_Server.index.html文件"));
app.UseIpLimitMiddle();
-app.UseApiLogMiddleware();
+//app.UseApiLogMiddleware();
+app.UseApiLogMiddlewareNew();
app.UseCors(AppSettings.Get(new string[] { "Cors", "PolicyName" }));
@@ -148,4 +169,14 @@
app.MapControllers();
+#region 应用启动时立即清理一次
+//Task.Run(async () =>
+//{
+// // 等待应用完全启动
+// await Task.Delay(30000);
+// var cleanupService = app.Services.GetRequiredService<LogCleanupService>();
+// await cleanupService.ManualCleanup(90);
+//});
+#endregion
+
app.Run();
--
Gitblit v1.9.3