System.Diagnostics.Trace.Listeners.Add(new ConsoleTraceListener()); // add console as output destination System.Diagnostics.Trace.WriteLine("Starting program...", TraceLevel.Info); // write an informational message System.Diagnostics.Trace.WriteLine("Error: " + ex.Message, TraceLevel.Error); // write an error message with an exceptionIn the first example, we add a console trace listener to output messages to the console. In the second example, we write an informational message with a specified TraceLevel. In the third example, we write an error message with an exception attached to it. TraceLevel is part of the System.Diagnostics package library in C#.