Using system;
Using system. Collections. Generic;
Using system. text;
Using system. diagnostics;
Namespace coninfo
{
Class Program
{
Static void main (string [] ARGs)
{
// Initialize the variable to include the product information
String sprodname = "widget ";
Int iunitqty = 100;
Double dunitcost = 1.03;
// create a textwritertracelistener object for the text file "console" window (tr1) and output.txt (tr2,
// Add each object to the debug listeners collection:
textwritertracelistener tr1 = new textwritertracelistener (system. console. out);
debug. listeners. add (tr1);
textwritertracelistener tr2 = new textwritertracelistener (system. io. file. createtext ("output.txt");
debug. listeners. add (tr2);
// Specify the message generated by the class as the first input parameter of the writeline method. Press CTRL + ALT + O to make sure the "output" window is visible.
Debug. writeline ("debug information-product starting ");
// For clarity and ease of reading, use the indent method to indent the message following the "output" Window
Debug. indent ();
Debug. writeline ("the product name is" + sprodname );
Debug. writeline ("the available units on hand are" + iunitqty. tostring ());
Debug. writeline ("the per unit cost is" + dunitcost. tostring ());
// To be clear and easy to read, use the unindent method to remove the indentation generated by the debug class for subsequent messages.
// When you use indent and unindent together, the reader can divide the output into groups.
Debug. unindent ();
Debug. writeline ("debug information-product ending ");
// you can use the writeline method to display the namespace and class name of an existing object.
// For example, the following Code shows System in the "output" window. XML. xmldocument namespace
system. XML. xmldocument oxml = new system. XML. xmldocument ();
debug. writeline (oxml);
// you can specify a category as the second optional input parameter of the writeline method.
// If you specify a category, the format of the "output" window message is "category: Message ".
// For example, the first line of the following code displays "field: the product name is widget" in the "output" window:
debug. writeline ("the product name is" + sprodname, "field");
debug. writeline ("the units on hand are" + iunitqty, "field");
debug. writeline ("the per unit cost is" + dunitcost. tostring (), "field");
debug. writeline ("total cost is" + (iunitqty * dunitcost), "calc");
// The "output" window displays messages only when the specified condition is calculated as true using the writelineif method of the debug class.
// the condition to be calculated is the first input parameter of the writelineif method.
// The second parameter of writelineif is displayed only when the condition of the first parameter is calculated as true.
debug. writelineif (iunitqty> 50, "This message will appear");
debug. writelineif (iunitqty <50, "This message will not appear");
// Use the assert method of the debug class to make the "output" window display messages only when the specified condition is calculated as false:
Debug. Assert (dunitcost> 1, "message will not appear ");
Debug. Assert (dunitcost <1, "message will appear since dunitcost <1 is false ");
// To ensure that each listener object receives all its output, call the flush method for the debug Buffer:
Debug. Flush ();
}
}
}