Debug Trace

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();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值