在 MiGu 侧落地日志定时清理与磁盘空间告警。
系统配置可开关清理策略;日志管理页支持查看/保存清理选项。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,7 +7,7 @@ namespace MiGu.Server.Configs;
|
||||
/// <summary>
|
||||
/// 配置中心存储(内存 + JSON 文件持久化占位)。
|
||||
/// 前 14 个 section 对应 ARCHITECTURE.md §9 的 13+1 维度;外加 deployment —— 登录后「配置向导」的部署画像。
|
||||
/// 真实落地时由 SimpleShared.Persistence 接入 EF Core,并配合 YARP 下发至 SimpleLite。
|
||||
/// 真实落地时由 SimpleShared.Persistence 接入 EF Core,并配合 YARP 下发至 Simple3。
|
||||
/// </summary>
|
||||
public sealed class ConfigStore
|
||||
{
|
||||
@@ -99,6 +99,58 @@ public sealed class ConfigStore
|
||||
return Put("deployment", el);
|
||||
}
|
||||
|
||||
public LogCleanupOptions GetLogCleanup()
|
||||
{
|
||||
var env = Get("system");
|
||||
return env.Payload switch
|
||||
{
|
||||
SystemConfig sc => (sc.LogCleanup ?? new LogCleanupOptions()).Clamp(),
|
||||
JsonElement el => ParseLogCleanup(el),
|
||||
_ => LogCleanupOptions.CreateDefaults()
|
||||
};
|
||||
}
|
||||
|
||||
public Envelope PutLogCleanup(LogCleanupOptions options)
|
||||
{
|
||||
var opt = (options ?? new LogCleanupOptions()).Clamp();
|
||||
Dictionary<string, JsonElement> dict;
|
||||
try
|
||||
{
|
||||
var current = Get("system").Payload;
|
||||
var el = current is JsonElement je
|
||||
? je
|
||||
: JsonSerializer.SerializeToElement(current, _jsonOpts);
|
||||
dict = el.ValueKind == JsonValueKind.Object
|
||||
? JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(el.GetRawText()) ?? new()
|
||||
: new Dictionary<string, JsonElement>();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "读取 system 配置失败,按空对象合并 logCleanup");
|
||||
dict = new Dictionary<string, JsonElement>();
|
||||
}
|
||||
|
||||
dict["logCleanup"] = JsonSerializer.SerializeToElement(opt, _jsonOpts);
|
||||
var merged = JsonSerializer.SerializeToElement(dict, _jsonOpts);
|
||||
return Put("system", merged);
|
||||
}
|
||||
|
||||
private LogCleanupOptions ParseLogCleanup(JsonElement el)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (el.ValueKind == JsonValueKind.Object && el.TryGetProperty("logCleanup", out var nested))
|
||||
return (nested.Deserialize<LogCleanupOptions>(_jsonOpts) ?? new LogCleanupOptions()).Clamp();
|
||||
var sc = el.Deserialize<SystemConfig>(_jsonOpts);
|
||||
return (sc?.LogCleanup ?? new LogCleanupOptions()).Clamp();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "反序列化 logCleanup 失败,回退默认值");
|
||||
return LogCleanupOptions.CreateDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
private DeploymentProfile SafeDeserializeDeployment(JsonElement el)
|
||||
{
|
||||
try { return el.Deserialize<DeploymentProfile>(_jsonOpts) ?? DeploymentProfile.Default(); }
|
||||
|
||||
Reference in New Issue
Block a user