I need indent and unindent 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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With