Search code examples
c#system.diagnostics

Indentation in a custom TraceListener


How should I implement supporting indentation in a custom TraceListener?

Trace.Indent();
// or
Trace.Unindent();

Does not work even if there is an implementation for:

protected override void WriteIndent() { ... }

In that custom TraceListener.

Am I missing something?


Solution

  • I have figured it out as those 2 static methods of Trace change IndentLevel. So I am doing this:

    ...
    if (entry.IndentLevel > 0)
        writer.WriteLine(
            new string(' ', entry.IndentLevel * IndentSize) +
    ...