You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace LogStudy.TraceLog
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 自定义跟踪监听器
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class CustomTraceListener : TraceListener
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 因为重写了Write方法:给进什么的,需要自行处理。否则缩进等设置不起作用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
public override void Write(string? message)
|
|
|
|
|
{
|
|
|
|
|
if (message == null || message?.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//处理缩进
|
|
|
|
|
var preText = string.Empty;
|
|
|
|
|
if (base.NeedIndent)
|
|
|
|
|
{
|
|
|
|
|
preText += new string(' ', base.IndentLevel * base.IndentSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.Write($"{preText}{message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 因为重写了Write方法:给进什么的,需要自行处理。否则缩进等设置不起作用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
public override void WriteLine(string? message)
|
|
|
|
|
{
|
|
|
|
|
if (message == null || message?.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//处理缩进
|
|
|
|
|
var preText = string.Empty;
|
|
|
|
|
if (base.NeedIndent)
|
|
|
|
|
{
|
|
|
|
|
preText += new string(' ', IndentLevel * IndentSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"{preText}{message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|