fix: 首次启动无法创建日志文件夹;Config 使用了错误的锁
This commit is contained in:
1 parent
473ac94d63
commit
d3b9ccde9c
2 files changed
+9
-7
No files matched your search
@@ -40,7 +40,7 @@ public class JsonConfigProvider : IConfigProvider {
|
|||||||
|
|
||||||
public void Set<T>(string key, T? value, bool encrypted) {
|
public void Set<T>(string key, T? value, bool encrypted) {
|
||||||
cache[key] = value;
|
cache[key] = value;
|
||||||
lock (json) {
|
lock (this) {
|
||||||
if (value is null) {
|
if (value is null) {
|
||||||
// 直接在 JSON 中表示为 null
|
// 直接在 JSON 中表示为 null
|
||||||
json.Value[key] = JValue.CreateNull();
|
json.Value[key] = JValue.CreateNull();
|
||||||
@@ -62,7 +62,7 @@ public class JsonConfigProvider : IConfigProvider {
|
|||||||
public T? Read<T>(string key, T? defaultValue, bool encrypted) {
|
public T? Read<T>(string key, T? defaultValue, bool encrypted) {
|
||||||
if (cache.TryGetValue(key, out var cachedValue)) return (T?) cachedValue; // 读取缓存
|
if (cache.TryGetValue(key, out var cachedValue)) return (T?) cachedValue; // 读取缓存
|
||||||
JToken entry;
|
JToken entry;
|
||||||
lock (json) {
|
lock (this) {
|
||||||
if (!json.Value.TryGetValue(key, out entry!)) return defaultValue; // 未找到该键
|
if (!json.Value.TryGetValue(key, out entry!)) return defaultValue; // 未找到该键
|
||||||
entry = entry.DeepClone();
|
entry = entry.DeepClone();
|
||||||
}
|
}
|
||||||
@@ -86,15 +86,15 @@ public class JsonConfigProvider : IConfigProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool HasValue(string key) {
|
public bool HasValue(string key) {
|
||||||
lock (json) return json.Value.ContainsKey(key);
|
lock (this) return json.Value.ContainsKey(key);
|
||||||
}
|
}
|
||||||
public void Remove(string key) {
|
public void Remove(string key) {
|
||||||
lock (json) json.Value.Remove(key);
|
lock (this) json.Value.Remove(key);
|
||||||
cache.TryRemove(key, out _);
|
cache.TryRemove(key, out _);
|
||||||
MakeDirty();
|
MakeDirty();
|
||||||
}
|
}
|
||||||
public void DiscardCache() {
|
public void DiscardCache() {
|
||||||
lock (json) InitJson();
|
lock (this) InitJson();
|
||||||
cache.Clear();
|
cache.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ public class JsonConfigProvider : IConfigProvider {
|
|||||||
public void Save() {
|
public void Save() {
|
||||||
if (!isDirty) return;
|
if (!isDirty) return;
|
||||||
isDirty = false;
|
isDirty = false;
|
||||||
lock (json) FileUtils.Write(filePath, json.Value.ToString(Formatting.Indented));
|
lock (this) FileUtils.Write(filePath, json.Value.ToString(Formatting.Indented));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -323,7 +323,9 @@ public class FileLogger : BaseLogger, IDisposable {
|
|||||||
Logger.Warn(ex, "整理日志文件失败");
|
Logger.Warn(ex, "整理日志文件失败");
|
||||||
}
|
}
|
||||||
// 新建 writer
|
// 新建 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 };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
Reference in new issue
Block a user