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

@@ -10,4 +10,10 @@
<PackageReference Include="NLog" Version="6.1.3" />
</ItemGroup>
<ItemGroup>
<None Update="Nlog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -12,23 +12,23 @@ namespace Logger
{
public static readonly ILogger Logger = LogManager.GetLogger("InfoLogger");
public static readonly ILogger sqlLogger = LogManager.GetLogger("SqlLogger");
public static IProgress<(string message, string color, int depth)> Progress { get; set; }
public static IProgress<(string scope, string message, string color, int depth)> Progress { get; set; }
static LoggerHelper()
{
Progress = new Progress<(string message, string color, int depth)>();
Progress = new Progress<(string scope, string message, string color, int depth)>();
}
public static void InfoWithNotify(string message, int depth = 0)
{
Logger.Info(message); // 写入 NLog
NotifyUI(message, "blue", depth); // 触发UI显示
}
public static void SuccessWithNotify(string message, int depth = 0)
public static void InfoWithNotify(string scope, string message, int depth = 0)
{
Logger.Info(message);
NotifyUI(message, "lightgreen", depth);
NotifyUI(scope, message, "blue", depth);
}
public static void WarnWithNotify(string message, string stackTrace = null, int depth = 0)
public static void SuccessWithNotify(string scope, string message, int depth = 0)
{
Logger.Info(message);
NotifyUI(scope, message, "lightgreen", depth);
}
public static void WarnWithNotify(string scope, string message, string stackTrace = null, int depth = 0)
{
if (!string.IsNullOrEmpty(stackTrace))
{
@@ -37,10 +37,10 @@ namespace Logger
}
Logger.Warn(message);
NotifyUI(message, "orange", depth);
NotifyUI(scope, message, "orange", depth);
}
public static void ErrorWithNotify(string message, string stackTrace = null, int depth = 0)
public static void ErrorWithNotify(string scope, string message, string stackTrace = null, int depth = 0)
{
if (!string.IsNullOrEmpty(stackTrace))
{
@@ -49,11 +49,11 @@ namespace Logger
}
Logger.Error(message);
NotifyUI(message, "red", depth);
NotifyUI(scope, message, "red", depth);
}
private static void NotifyUI(string message, string color, int depth)
private static void NotifyUI(string scope, string message, string color, int depth)
{
Progress.Report((message, color, depth));
Progress.Report((scope, message, color, depth));
}
public static void Info(string message, int depth = 0)
@@ -95,20 +95,18 @@ namespace Logger
foreach (var line in lines)
{
// 匹配你项目的命名空间路径
if (line.Contains("ADP"))
{
// 提取 "in 文件路径:line 行号"
var match = Regex.Match(line, @"in (.+?):line (\d+)");
if (match.Success)
{
return match.Value; // 返回类似 C:\...\MainViewModel.cs:line 37
return match.Value;
}
return line.Trim();
}
}
return lines[0].Trim(); // 如果找不到就返回第一条
return lines[0].Trim();
}
}
}