我需要像 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/