-1

I have a WPF application which is intended to work offline in a 64-GB-RAM/2-CPU-Core devices. I have delivered the output directory to a tester to test the application...

The application is logging messages using different methods: Debug.WriteLine(), Trace.WriteLine() and Console.WriteLine() ... I have seen some tools like TraceSpy which can show Debug and Trace messages..

I wonder if there is a simple way to watch Console.WriteLine() messages at the testing device? or I have to change all my Console.WriteLine() to Trace.WriteLine()?

1 Answers1

0

When you debug a window application, the console output is redirected to the Visual Studio Output Window. Maybe this work also with other tool like TraceSpy.

Else you can redirect where the console write with Console.SetOut :

class Program
{
    static void Main(string[] args)
    {
        Console.SetOut(new TraceWritter());
        Console.WriteLine("Log : Something happened!");
        ...
    }
}

You just need implement a custom TextWriter and override only Write(char) method :

Notes to Implementers

A derived class must minimally implement the Write(Char) method to make a useful instance of TextWriter.

public class TraceWritter : TextWriter
{
    public override Encoding Encoding => System.Text.Encoding.Default;

    public override void Write(char value)
    {
        Debug.Write(value);
    }
}
vernou
  • 6,818
  • 5
  • 30
  • 58