Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing C# debug output to .txt file

I'm running code on a microcontroller with .NET Micro Framework, and I want my debug output to write to a text file. How does this work?

like image 926
755 Avatar asked Oct 28 '11 07:10

755


1 Answers

Use Trace. It is designed to do what you need.

using System;
using System.Diagnostics;

class Test
{
    static void Main()
    {
       Trace.Listeners.Add(new TextWriterTraceListener("yourlog.log"));
       Trace.AutoFlush = true;
       Trace.Indent();
       Trace.WriteLine("Entering Main");
       Console.WriteLine("Hello World.");
       Trace.WriteLine("Exiting Main");
       Trace.Unindent();
       Trace.Flush();
    }
}
like image 89
Ekk Avatar answered Oct 11 '22 03:10

Ekk