log日志bug修改
This commit is contained in:
41
UIShare/GlobalVariable/ScopeLogDispatcher.cs
Normal file
41
UIShare/GlobalVariable/ScopeLogDispatcher.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user