using System;
using System.Diagnostics;
//确保 Debug 是当前的解决方案配置。
//如果“解决方案资源管理器”窗口不可见,请按 CTRL+ALT+L 组合键以显示此窗口。
//右键单击“conInfo”,然后单击“属性”。
//在 conInfo 属性页左窗格中,在“配置”文件夹下,请确保箭头指向“调试”。
//在“配置”文件夹上面的“配置”下拉列表框中,单击“活动(调试)”或“调试”,然后单击“确定”。
//按 CTRL+ALT+O 以显示“输出”窗口。
//按 F5 键以运行该代码。在出现“断言失败”对话框时,单击“忽略”。
class Class1
{
[STAThread]
static void Main(string[] args)
{
string sProdName = "Widget";
int iUnitQty = 100;
double dUnitCost = 1.03;
//将类生成的消息指定为 WriteLine 方法的第一个输入参数。按 CTRL+ALT+O 组合键以确保“输出”窗口可见。
Debug.WriteLine("Debug Information-Product Starting ");
//为了清晰易读,请使用 Indent 方法在“输出”窗口中缩进后面的消息:
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());
System.Xml.XmlDocument oxml = new System.Xml.XmlDocument();
Debug.WriteLine(oxml);
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");
Debug.WriteLineIf(iUnitQty > 50, "This message WILL appear");
Debug.WriteLineIf(iUnitQty < 50, "This message will NOT appear");
Debug.Assert(dUnitCost > 1, "Message will NOT appear");
Debug.Assert(dUnitCost < 1, "Message will appear since dUnitcost < 1 is false");
//使用 System.Console.Out 属性指定“控制台”窗口作为输出目标。
//使用 System.IO.File.CreateText("FileName.txt") 语句指定文本文件 (.txt) 作为输出目标。
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);
Debug.WriteLine("The product name is " + sProdName);
Debug.WriteLine("The available units on hand are" + iUnitQty);
Debug.WriteLine("The per unit cost is " + dUnitCost);
Debug.Unindent();
Debug.WriteLine("Debug Information-Product Ending");
Debug.Flush();
Trace.WriteLine("Trace Information-Product Starting ");
Trace.Indent();
Trace.WriteLine("The product name is " + sProdName);
Trace.WriteLine("The product name is" + sProdName, "Field");
Trace.WriteLineIf(iUnitQty > 50, "This message WILL appear");
Trace.Assert(dUnitCost > 1, "Message will NOT appear");
Trace.Unindent();
Trace.WriteLine("Trace Information-Product Ending");
Trace.Flush();
Console.ReadLine();
}
}
Debug Trace
最新推荐文章于 2021-04-15 18:22:57 发布