在 MiGu 侧落地日志定时清理与磁盘空间告警。
系统配置可开关清理策略;日志管理页支持查看/保存清理选项。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
namespace MiGu.Server.Configs;
|
||||
|
||||
/// <summary>
|
||||
/// 日志清理与磁盘告警(system.logCleanup)。字段对齐 Simple3 <c>LogCleanupOptions</c>。
|
||||
/// </summary>
|
||||
public sealed class LogCleanupOptions
|
||||
{
|
||||
/// <summary>是否启用后台自动清理。关闭后仅「立即清理」可手动触发。默认 true。</summary>
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
/// <summary>保留天数:删除 log/ 下 LastWriteTime 早于「现在 − N 天」的 *.log。默认 30,最小 1。</summary>
|
||||
public int RetentionDays { get; set; } = 30;
|
||||
|
||||
/// <summary>后台清理间隔(小时)。默认 24;<= 0 归一为 1。</summary>
|
||||
public int CheckIntervalHours { get; set; } = 24;
|
||||
|
||||
/// <summary>启动时先执行一次清理。默认 true。</summary>
|
||||
public bool RunOnStartup { get; set; } = true;
|
||||
|
||||
/// <summary>是否启用磁盘剩余空间不足告警。默认 true。</summary>
|
||||
public bool DiskAlertEnabled { get; set; } = true;
|
||||
|
||||
/// <summary>日志所在盘剩余低于该值(GB)时告警。默认 5。</summary>
|
||||
public double DiskFreeAlertGB { get; set; } = 5;
|
||||
|
||||
/// <summary>磁盘检测间隔(分钟)。默认 30;<= 0 归一为 30。</summary>
|
||||
public int DiskCheckIntervalMinutes { get; set; } = 30;
|
||||
|
||||
public static LogCleanupOptions CreateDefaults() => new();
|
||||
|
||||
public LogCleanupOptions Clamp()
|
||||
{
|
||||
RetentionDays = Math.Clamp(RetentionDays, 1, 3650);
|
||||
CheckIntervalHours = Math.Max(1, CheckIntervalHours);
|
||||
if (DiskFreeAlertGB <= 0) DiskFreeAlertGB = 5;
|
||||
DiskCheckIntervalMinutes = DiskCheckIntervalMinutes <= 0 ? 30 : DiskCheckIntervalMinutes;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user