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.

58 lines
1.6 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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}");
}
}
}