From d3b9ccde9c212ccce552099ada11dad35f9551a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Thu, 2 Jul 2026 09:33:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A6=96=E6=AC=A1=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=88=9B=E5=BB=BA=E6=97=A5=E5=BF=97=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=EF=BC=9BConfig=20=E4=BD=BF=E7=94=A8=E4=BA=86?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/General/Config.cs | 12 ++++++------ Shared/General/Logger.cs | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Shared/General/Config.cs b/Shared/General/Config.cs index d336b0d..16da416 100644 --- a/Shared/General/Config.cs +++ b/Shared/General/Config.cs @@ -40,7 +40,7 @@ public class JsonConfigProvider : IConfigProvider { public void Set(string key, T? value, bool encrypted) { cache[key] = value; - lock (json) { + lock (this) { if (value is null) { // 直接在 JSON 中表示为 null json.Value[key] = JValue.CreateNull(); @@ -62,7 +62,7 @@ public class JsonConfigProvider : IConfigProvider { public T? Read(string key, T? defaultValue, bool encrypted) { if (cache.TryGetValue(key, out var cachedValue)) return (T?) cachedValue; // 读取缓存 JToken entry; - lock (json) { + lock (this) { if (!json.Value.TryGetValue(key, out entry!)) return defaultValue; // 未找到该键 entry = entry.DeepClone(); } @@ -86,15 +86,15 @@ public class JsonConfigProvider : IConfigProvider { } public bool HasValue(string key) { - lock (json) return json.Value.ContainsKey(key); + lock (this) return json.Value.ContainsKey(key); } public void Remove(string key) { - lock (json) json.Value.Remove(key); + lock (this) json.Value.Remove(key); cache.TryRemove(key, out _); MakeDirty(); } public void DiscardCache() { - lock (json) InitJson(); + lock (this) InitJson(); cache.Clear(); } @@ -109,7 +109,7 @@ public class JsonConfigProvider : IConfigProvider { public void Save() { if (!isDirty) return; isDirty = false; - lock (json) FileUtils.Write(filePath, json.Value.ToString(Formatting.Indented)); + lock (this) FileUtils.Write(filePath, json.Value.ToString(Formatting.Indented)); } } diff --git a/Shared/General/Logger.cs b/Shared/General/Logger.cs index 24ad3fb..d32fc15 100644 --- a/Shared/General/Logger.cs +++ b/Shared/General/Logger.cs @@ -323,7 +323,9 @@ public class FileLogger : BaseLogger, IDisposable { Logger.Warn(ex, "整理日志文件失败"); } // 新建 writer - writer = new StreamWriter(PathUtils.ForApi(Path.Combine(logFolder, $"{fileNamePrefix}1{fileNameSuffix}")), append: true) { AutoFlush = true }; + string logFilePath = PathUtils.ForApi(Path.Combine(logFolder, $"{fileNamePrefix}1{fileNameSuffix}")); + DirectoryUtils.Create(logFolder); + writer = new StreamWriter(logFilePath, append: true) { AutoFlush = true }; } ///