Tôi cần thụt lề và xử lý không giống như kiểu gốc trace class. Bất kỳ ý tưởng làm thế nào điều này có thể thực hiện với file log4net và giao diện điều khiển appender? cảm ơn bạnmẫu log4net là gì để có được tương đương với Trace.indent và trace.unindent
6
A
Trả lời
2
Tôi khuyên bạn nên bọc ứng dụng bảng điều khiển log4net trong một lớp học và thêm hỗ trợ thụt lề vào đó. Chúng tôi làm một cái gì đó tương tự với StringBuilder. Chúng tôi đã tạo một lớp FormattedStringBuilder có phương thức Tăng và Giảm mức thụt lề
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); } } }