Use Trace, it designs 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(""); Trace. WriteLine("Exiting Main"); Trace.Unindent(); Trace.Flush(); } }.
If you only want to trace to Console, then ConsoleTraceListener seems to be a clearer and more straight forward solution. But he asked to write into a file. – Ucodia Oct 28 at 8:11 I just update my answer, thanks to point me out the problem.
:) – Ekk Oct 28 at 8:13.
You will have to do something like this: // set up listener string filename = @"C:\listener. Txt"; FileStream traceLog = new FileStream( filename, FileMode. OpenOrCreate ); TextWriterTraceListener listener = new TextWriterTraceListener( traceLog ); // output to listener listener.
WriteLine( "Trace message here" ); // flush any open output before termination // maybe in an override of Form. OnClosed listener.Flush(); Taken from Here Another related Question.
The most flexible solution for using a out-of-the-box tracing is to make an application configuration file that will define trace listeners. Then, in your application, whenever you want to log something, just do: Trace. WriteLine(" this is a trace"); But the power of the TraceListener class lies into its granularity.
You can chose between Error, Info and Warning levels and define different log file for whatever level you need to trace. Using configuration files makes it also easier to disable tracing in your application because you don't need to recompile your application. For more informations on tracing system, check this MSDN article.
1 I think you answer my answer/question you solution should work in . NET Micro Framework. I'am still using debugview.exe.
– JPBlanc Oct 28 at 8:37.
My answer is a king of question. In Win32 programming I track the problems using the OutputDebugString() function. This allow me to see the output debug to visual studio during debug.
You can get the data in debugView tool. In . NET I use : System.Diagnostics.Debug.
WriteLine("Text in mode Debug"); // for debug only System.Diagnostics.Trace. WriteLine("Text in mode Trace"); // for debug and release Can you use this with . NET Micro Framework?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.