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

@@ -59,6 +59,10 @@ namespace ADP
}
protected override void OnInitialized()
{
// 配置全局日志分发器:按 CurrentScope 路由到对应 LogArea
var globalInfo = Container.Resolve<GlobalInfo>();
LoggerHelper.Progress = new ScopeLogDispatcher(globalInfo);
//初始化数据库
//DatabaseConfig.SetTenant(10001);
//DatabaseConfig.InitMySql("127.0.0.1",3306,"ADP","root","123456");

View File

@@ -6,6 +6,7 @@ using Notifications.Wpf.Core;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
@@ -226,7 +227,7 @@ namespace ADP.ViewModels
if (targetContext.RunState == "运行")
{
targetContext.SingleStep = false;
LoggerHelper.InfoWithNotify($"{_globalInfo.UserName} 执行工位 [{runningScope}] 运行命令");
LoggerHelper.InfoWithNotify(runningScope, $"{_globalInfo.UserName} 执行工位 [{runningScope}] 运行命令");
targetContext.RunState = "暂停";
targetContext.RunIcon = PackIconKind.Pause;
@@ -252,7 +253,7 @@ namespace ADP.ViewModels
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"工位 [{runningScope}] 异常中止: {ex.Message}");
LoggerHelper.ErrorWithNotify(runningScope, $"工位 [{runningScope}] 异常中止: {ex.Message}");
}
// 💡 测试正常完毕或取消:停止当前工位的 SW并将最终时间固化到 RunningTime 字段中
@@ -285,7 +286,7 @@ namespace ADP.ViewModels
}
else // 用户点击了暂停
{
LoggerHelper.InfoWithNotify($"{_globalInfo.UserName} 点击工位 [{runningScope}] 暂停命令");
LoggerHelper.InfoWithNotify(runningScope, $"{_globalInfo.UserName} 点击工位 [{runningScope}] 暂停命令");
targetContext.SingleStep = true;
targetContext.IsStop = true;
targetContext.RunState = "运行";
@@ -308,7 +309,7 @@ namespace ADP.ViewModels
if (targetContext.RunState == "运行")
{
targetContext.SingleStep = true;
LoggerHelper.InfoWithNotify($"{_globalInfo.UserName} 执行工位 [{runningScope}] 单步执行命令");
LoggerHelper.InfoWithNotify(runningScope, $"{_globalInfo.UserName} 执行工位 [{runningScope}] 单步执行命令");
targetContext.RunState = "暂停";
targetContext.RunIcon = PackIconKind.Pause;
@@ -334,7 +335,7 @@ namespace ADP.ViewModels
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"工位 [{runningScope}] 单步执行异常: {ex.Message}");
LoggerHelper.ErrorWithNotify(runningScope, $"工位 [{runningScope}] 单步执行异常: {ex.Message}");
}
// 💡 单步单步完成后会被 StepRunning 挂起,在此暂时停止 SW
@@ -378,7 +379,7 @@ namespace ADP.ViewModels
return;
}
LoggerHelper.InfoWithNotify($"{_globalInfo.UserName} 执行工位 [{runningScope}] 复位命令");
LoggerHelper.InfoWithNotify(runningScope, $"{_globalInfo.UserName} 执行工位 [{runningScope}] 复位命令");
_executionTasks.TryGetValue(runningScope, out var currentTask);
_errorExecutionTasks.TryGetValue(runningScope, out var errorTask);
@@ -428,7 +429,7 @@ namespace ADP.ViewModels
return;
}
LoggerHelper.InfoWithNotify($"{_globalInfo.UserName} 执行工位 [{runningScope}] 异常流程命令");
LoggerHelper.InfoWithNotify(runningScope, $"{_globalInfo.UserName} 执行工位 [{runningScope}] 异常流程命令");
// 💡 异常测试启动计时
targetContext.SW.Start();
@@ -445,7 +446,7 @@ namespace ADP.ViewModels
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"工位 [{runningScope}] 异常流程执行出错: {ex.Message}");
LoggerHelper.ErrorWithNotify(runningScope, $"工位 [{runningScope}] 异常流程执行出错: {ex.Message}");
}
// 💡 异常测试结束停止计时
@@ -479,7 +480,7 @@ namespace ADP.ViewModels
{
CurrentConfig.DefaultProgramFilePath = targetContext.CurrentFilePath;
ConfigService.Save(CurrentConfig);
LoggerHelper.SuccessWithNotify($"工位 [{runningScope}] 已成功将当前程序设为默认启动程序");
LoggerHelper.SuccessWithNotify(runningScope, $"工位 [{runningScope}] 已成功将当前程序设为默认启动程序");
}
}
@@ -505,7 +506,7 @@ namespace ADP.ViewModels
}
targetContext.Program.Parameters.Add(item);
}
LoggerHelper.InfoWithNotify($"工位 [{runningScope}] 创建了空程序文件");
LoggerHelper.InfoWithNotify(runningScope, $"工位 [{runningScope}] 创建了空程序文件");
// 如果当前正看着该工位,刷新 UI 显示
if (_globalInfo.CurrentScope == runningScope) RefreshAllContextProperties();
@@ -539,7 +540,7 @@ namespace ADP.ViewModels
// 确认文件存在
if (!File.Exists(filePath))
{
LoggerHelper.ErrorWithNotify($"文件不存在: {filePath}");
LoggerHelper.ErrorWithNotify(runningScope, $"文件不存在: {filePath}");
return;
}
@@ -551,7 +552,7 @@ namespace ADP.ViewModels
if (program == null)
{
LoggerHelper.WarnWithNotify($"文件格式不正确或为空: {filePath}");
LoggerHelper.WarnWithNotify(runningScope, $"文件格式不正确或为空: {filePath}");
return;
}
@@ -571,7 +572,7 @@ namespace ADP.ViewModels
}
}
LoggerHelper.SuccessWithNotify($"工位 [{runningScope}] 成功打开文件: {filePath}");
LoggerHelper.SuccessWithNotify(runningScope, $"工位 [{runningScope}] 成功打开文件: {filePath}");
// 💡 3. 安全调用异步复位,确保重置的是对应工位的数据
// 注意:由于在 OnRestoration 内部第一行也做了快照拦截,
@@ -580,7 +581,7 @@ namespace ADP.ViewModels
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"工位 [{runningScope}] 打开文件失败: {ex.Message}");
LoggerHelper.ErrorWithNotify(runningScope, $"工位 [{runningScope}] 打开文件失败: {ex.Message}");
}
finally
{
@@ -619,7 +620,7 @@ namespace ADP.ViewModels
// 💡 3. 调用你的底层文件保存逻辑,传入快照工位的 Program 模型
SaveProgramToFile(targetContext.CurrentFilePath, targetContext.Program);
LoggerHelper.InfoWithNotify($"{_globalInfo.UserName} 另存为文件成功: {saveFileDialog.FileName}");
LoggerHelper.InfoWithNotify(runningScope, $"{_globalInfo.UserName} 另存为文件成功: {saveFileDialog.FileName}");
if (_globalInfo.CurrentScope == runningScope) RefreshAllContextProperties();
}
@@ -644,7 +645,7 @@ namespace ADP.ViewModels
// 💡 3. 持久化当前快照工位的 Program
SaveProgramToFile(targetContext.CurrentFilePath, targetContext.Program);
LoggerHelper.SuccessWithNotify($"工位 [{runningScope}] 程序保存成功!");
LoggerHelper.SuccessWithNotify(_globalInfo.CurrentScope,$"工位 [{runningScope}] 程序保存成功!");
}
// 💡 辅助方法:建议将你的通用序列化落盘代码调整为接收 ProgramVM 参数,提高复用性
@@ -657,7 +658,7 @@ namespace ADP.ViewModels
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"写入程序文件失败: {ex.Message}");
LoggerHelper.ErrorWithNotify(_globalInfo.CurrentScope,$"写入程序文件失败: {ex.Message}");
}
}