What is the log4net template to get the equivalent of Trace.indent and trace.unindent

I need indentation and unindend handling as a native trace class . Any ideas how this can be done with the log4net file and the console application? thanks

+6
source share
1 answer

I would recommend wraping appender app log4net in the class and adding indentation support there. We are doing something similar to StringBuilder. We created the FormattedStringBuilder class, which has methods for increasing and decreasing the indentation level.

  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);
         }
     }
 }
+2
source

Source: https://habr.com/ru/post/896240/


All Articles