Trace Listerners

This code shows how to use the default trace listener that sends the race output to the Output window in the IDE. It also shows how to readd the default trace listener if the trace listeners collection has been cleared. The default trace listener by default is added to the trace listeners collection.

Use System.Diagnostics namespace

string ProductType = "Computer";
int Price = 2000;

// Create instance of the default trace listener
DefaultTraceListener tlDefault = new DefaultTraceListener();

// Clear all trace listeners from the collection

// Add the default listener to the collection

Trace.WriteLine("****** Trace OutPut Start ******");
Trace.WriteLine("Output window trace information");
Trace.WriteLine("This line is indented");
Trace.WriteLine("Product Type = " + ProductType);
Trace.WriteLine("Price = $" + Price);
Trace.WriteLineIf(Price > 1800, "Price > $1800");
Trace.WriteLine("****** Trace Output End ******");


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: