400,259 Members | 3,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 400,259 IT Pros & Developers. It's quick & easy.

CustomTraceListener Question

CGuy
P: n/a
Hi,

I have a question. I have implemented a custom trace listener (derived from
the TextWriterTraceListener type).
Now, I add this custom trace listener to the list of listeners and then call
a Trace.Indent() before I write to the trace. But the file produced by my
CustomTraceListener does not indent the text. How do I do this?

CGuy
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


Noah Coad [MVP .NET/C#]
P: n/a
The TraceListener class has an "IndentLevel" property that you can access to
obtain the level of indenting you should use. Here is an example I wrote
for you:

class Class1
{
public Class1(string[] args)
{
System.Diagnostics.Debug.Listeners.Clear();
System.Diagnostics.Debug.Listeners.Add(new DateStampTraceLisener());
Debug.WriteLine("Testing");
Debug.Indent();
Debug.WriteLine("Testing Indent");
}

#region Application Entry Point
[STAThread]
static void Main(string[] args)
{
new Class1(args);
Console.WriteLine("\nPress [ENTER] to exit...");
Console.ReadLine();
}
#endregion
}

class DateStampTraceLisener : TraceListener
{
public override void Write(string info)
{ Console.WriteLine("".PadLeft(IndentLevel * 2, ' ') + DateTime.Now + "
" + info); }

public override void WriteLine(string info)
{ Write(info + "\n"); }
}

"CGuy" <cguy@csharp.net> wrote in message
news:uinU7A9SDHA.3768@tk2msftngp13.phx.gbl...
Hi,

I have a question. I have implemented a custom trace listener (derived from the TextWriterTraceListener type).
Now, I add this custom trace listener to the list of listeners and then call a Trace.Indent() before I write to the trace. But the file produced by my
CustomTraceListener does not indent the text. How do I do this?

CGuy

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.