28 lines
886 B
C#
28 lines
886 B
C#
using System.Diagnostics;
|
|
|
|
namespace WinFormsApp3
|
|
{
|
|
/// <summary>
|
|
/// 截图预览诊断日志:exe 目录下 preview_debug.log。
|
|
/// 挂起类问题光看界面定位不到,必须把每一步(含线程号)落到磁盘上。
|
|
/// </summary>
|
|
public static class PreviewLog
|
|
{
|
|
private static readonly object Gate = new();
|
|
private static readonly string FilePath = Path.Combine(AppContext.BaseDirectory, "preview_debug.log");
|
|
|
|
public static void Write(string message)
|
|
{
|
|
string line = $"{DateTime.Now:HH:mm:ss.fff} [T{Thread.CurrentThread.ManagedThreadId:D2}] {message}";
|
|
try
|
|
{
|
|
lock (Gate) File.AppendAllText(FilePath, line + Environment.NewLine);
|
|
}
|
|
catch
|
|
{
|
|
// 日志写失败不影响功能
|
|
}
|
|
}
|
|
}
|
|
}
|