2011-08-30 6 views

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