diff --git a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs index 0f549d03dc..5c27687c4f 100644 --- a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs @@ -126,14 +126,30 @@ public partial class CopilotViewModel : Screen /// The font color. /// The font weight. /// Whether show time. - public void AddLog(string content, string color = UiLogColor.Trace, string weight = "Regular", bool showTime = true) + public void AddLog(string? content, string color = UiLogColor.Trace, string weight = "Regular", bool showTime = true) { + if (string.IsNullOrEmpty(content)) + { + return; + } + Execute.OnUIThread(() => { LogItemViewModels.Add(new LogItemViewModel(content, color, weight, "HH':'mm':'ss", showTime: showTime)); if (showTime) { - _logger.Information(content); + switch (color) + { + case UiLogColor.Error: + _logger.Error("{Content}", content); + break; + case UiLogColor.Warning: + _logger.Warning("{Content}", content); + break; + default: + _logger.Information("{Content}", content); + break; + } } }); diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index ec449047e6..e8f7a1a903 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -884,13 +884,29 @@ public class TaskQueueViewModel : Screen /// The font color. /// The font weight. /// The toolTip - public void AddLog(string content, string color = UiLogColor.Trace, string weight = "Regular", ToolTip? toolTip = null) + public void AddLog(string? content, string color = UiLogColor.Trace, string weight = "Regular", ToolTip? toolTip = null) { + if (string.IsNullOrWhiteSpace(content)) + { + return; + } + Execute.OnUIThread(() => { var log = new LogItemViewModel(content, color, weight, toolTip: toolTip); LogItemViewModels.Add(log); - _logger.Information("{Content}", content); + switch (color) + { + case UiLogColor.Error: + _logger.Error("{Content}", content); + break; + case UiLogColor.Warning: + _logger.Warning("{Content}", content); + break; + default: + _logger.Information("{Content}", content); + break; + } }); }