CustomTraceListener Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CGuy

    #1

    CustomTraceListener Question

    Hi,

    I have a question. I have implemented a custom trace listener (derived from
    the TextWriterTrace Listener 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
    CustomTraceList ener does not indent the text. How do I do this?

    CGuy


  • Noah Coad [MVP .NET/C#]

    #2
    Re: CustomTraceList ener Question

    The TraceListener class has an "IndentLeve l" 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.Diagnost ics.Debug.Liste ners.Clear();
    System.Diagnost ics.Debug.Liste ners.Add(new DateStampTraceL isener());
    Debug.WriteLine ("Testing");
    Debug.Indent();
    Debug.WriteLine ("Testing Indent");
    }

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

    class DateStampTraceL isener : TraceListener
    {
    public override void Write(string info)
    { Console.WriteLi ne("".PadLeft(I ndentLevel * 2, ' ') + DateTime.Now + "
    " + info); }

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



    "CGuy" <cguy@csharp.ne t> wrote in message
    news:uinU7A9SDH A.3768@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi,
    >
    > I have a question. I have implemented a custom trace listener (derived[/color]
    from[color=blue]
    > the TextWriterTrace Listener type).
    > Now, I add this custom trace listener to the list of listeners and then[/color]
    call[color=blue]
    > a Trace.Indent() before I write to the trace. But the file produced by my
    > CustomTraceList ener does not indent the text. How do I do this?
    >
    > CGuy
    >
    >[/color]


    Comment

    Working...