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); } } }
精彩评论