开发者

what is the log4net pattern to get the equivalent of Trace.indent and trace.unindent

I need indent and 开发者_如何学Gounindent handling like the native trace class. Any ideas how this can done with log4net file and console appender ? thank you


I would recommend wraping the log4net console appender in a class and adding the indent support there. We do something similiar with StringBuilder. We created a FormattedStringBuilder class that has Increase and Decrease Indent level methods

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜