gpt4 book ai didi

c# - 获得 Trace.indent 和 trace.unindent 等价物的 log4net 模式是什么

转载 作者:太空狗 更新时间:2023-10-29 21:55:26 27 4
gpt4 key购买 nike

我需要像 native 一样的缩进和非缩进处理 trace class .有什么想法可以用 log4net 文件和控制台 appender 完成吗?谢谢

最佳答案

我建议将 log4net 控制台附加程序包装在一个类中,并在其中添加缩进支持。我们用 StringBuilder 做一些类似的事情。我们创建了一个具有增加和减少缩进级别方法的 FormattedStringBuilder 类

private const string Indent = "\t";private readonly int IndentLength = Indent.Length;public void IncreaseIndent(){    // Increase indent    indentLevel++;    indentBuffer.Append(Indent);    // If new line already started, insert another indent at the beginning    if (!useIndent)    {        contentBuffer.Insert(0, Indent);    }}public void DecreaseIndent() {    // Only decrease the indent to zero.    if (indentLevel > 0)     {        indentLevel--;        // Remove an indent from the string, if applicable        if (indentBuffer.Length != 0)         {            indentBuffer.Remove(indentBuffer.Length - IndentLength, IndentLength);        }    }}

关于c# - 获得 Trace.indent 和 trace.unindent 等价物的 log4net 模式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7248764/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com