// Define trace and trace listener TraceSource mySource = new TraceSource("myTraceSource"); TextWriterTraceListener myListener = new TextWriterTraceListener("myOutput.txt"); mySource.Listeners.Add(myListener); // Log start of method mySource.TraceEvent(EventType.Start, 0, "Method Start"); // Do some work // Log end of method mySource.TraceEvent(EventType.Stop, 0, "Method Stop"); // Clean up mySource.Flush(); mySource.Close();
TraceSource mySource = new TraceSource("myTraceSource"); mySource.TraceData(EventType.Information, 0, new object[] { "Info message", DateTime.Now });This example shows how to use the EventType.Information event to log an information message along with some data. This can be useful for logging additional information that might help with troubleshooting. Package library: System.Diagnostics