Files
Ayay/SHH.CameraDashboard/Services/ProcessDashboardLogger.cs
2026-01-05 14:54:06 +08:00

37 lines
1.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using SHH.ProcessLaunchers;
using System.Diagnostics;
using System.Windows;
namespace SHH.CameraDashboard
{
/// <summary>
/// 启动器日志适配器
/// <para>将底层 ProcessManager 的日志桥接到 System.Diagnostics.Debug 和 MessageBox</para>
/// </summary>
public class ProcessDashboardLogger : ILauncherLogger
{
public void LogConsole(string processId, string message, bool isError)
{
// 将子进程的控制台输出转发到 VS 的输出窗口,方便调试
string prefix = isError ? "[STDERR]" : "[STDOUT]";
Debug.WriteLine($"{prefix} <{processId}>: {message}");
}
public void LogLifecycle(string processId, LogAction action, LogTrigger trigger, string reason, object payload = null)
{
string msg = $"[ProcessManager] {processId} - {action}: {reason}";
Debug.WriteLine(msg);
// 如果是严重错误(如资源超限被杀),弹窗提醒
if (trigger == LogTrigger.ResourceGuard && action == LogAction.Restart)
{
// 注意:确保在 UI 线程弹窗
Application.Current.Dispatcher.Invoke(() =>
{
MessageBox.Show($"进程 [{processId}] 资源异常!\n原因{reason}\n系统已执行自动重启。",
"资源管控警报", MessageBoxButton.OK, MessageBoxImage.Warning);
});
}
}
}
}