feat: Wpf日志文件输出分级

This commit is contained in:
status102
2025-12-21 00:59:15 +08:00
parent 19735b9018
commit ca47a8eaf9
2 changed files with 36 additions and 4 deletions

View File

@@ -126,14 +126,30 @@ public partial class CopilotViewModel : Screen
/// <param name="color">The font color.</param>
/// <param name="weight">The font weight.</param>
/// <param name="showTime">Whether show time.</param>
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;
}
}
});

View File

@@ -884,13 +884,29 @@ public class TaskQueueViewModel : Screen
/// <param name="color">The font color.</param>
/// <param name="weight">The font weight.</param>
/// <param name="toolTip">The toolTip</param>
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;
}
});
}