log日志bug修改

This commit is contained in:
hsc
2026-06-24 10:18:54 +08:00
parent c4470af013
commit 4deb785135
16 changed files with 169 additions and 101 deletions

View File

@@ -0,0 +1,41 @@
using Logger;
using System;
using System.Windows.Media;
namespace UIShare.GlobalVariable
{
/// <summary>
/// 作用域日志分发器:根据显式传入的 scope 参数把日志路由到对应
/// <see cref="ScopedContext.LogProgress"/>,实现每个台架/作用域拥有独立 LogArea。
/// </summary>
public class ScopeLogDispatcher : IProgress<(string scope, string message, string color, int depth)>
{
private readonly GlobalInfo _globalInfo;
public ScopeLogDispatcher(GlobalInfo globalInfo)
{
_globalInfo = globalInfo ?? throw new ArgumentNullException(nameof(globalInfo));
}
public void Report((string scope, string message, string color, int depth) value)
{
var scope = value.scope;
if (string.IsNullOrEmpty(scope)) return;
if (!_globalInfo.ContextDic.TryGetValue(scope, out var context)) return;
if (context?.LogProgress == null) return;
Brush? brush = null;
try
{
brush = (Brush)new BrushConverter().ConvertFromString(value.color);
}
catch
{
brush = Brushes.Black;
}
context.LogProgress.Report((value.message, brush, value.depth));
}
}
}