zoukankan      html  css  js  c++  java
  • C#调试类

    1  Debug类

    (1)提供一组帮助调试代码的方法和属性。

    (2)Debug.Listeners 属性 获取监视调试输出的侦听器集合.Listeners 集合被 DebugTrace 类共用;向任何一个类添加元素侦听器将会向两者同时添加。

    /* Create a listener that outputs to the console screen, and 
      * add it to the debug listeners. */
     TextWriterTraceListener myWriter = new 
        TextWriterTraceListener(System.Console.Out);
     Debug.Listeners.Add(myWriter);

    (3)实例:The following example uses Debug to indicate the beginning and end of a program's execution. The example also uses the Indent and Unindent methods to distinguish the tracing output.

    // Specify /d:DEBUG when compiling.
    
    using System;
    using System.Data;
    using System.Diagnostics;
    
    class Test
    {
        static void Main()
        {
           Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
           Debug.AutoFlush = true;
           Debug.Indent();
           Debug.WriteLine("Entering Main");
           Console.WriteLine("Hello World.");
           Debug.WriteLine("Exiting Main"); 
           Debug.Unindent();
        }
    }

    2 TextWriterTraceListener类

    (1)将跟踪或调试输出定向到 TextWriterStream,如 FileStream

    public class Sample
    {
    
    public static int Main(string[] args)
     {
        // Create a file for output named TestFile.txt.
        Stream myFile = File.Create("TestFile.txt");
     
        /* Create a new text writer using the output stream, and add it to
         * the trace listeners. */
        TextWriterTraceListener myTextListener = new 
           TextWriterTraceListener(myFile);
        Trace.Listeners.Add(myTextListener);
     
        // Write output to the file.
        Trace.Write("Test output ");
     
    
        // Flush the output.
        Trace.Flush(); 
    
        return 0;
     }
    
    }

    3  Trace Class

    (1)Provides a set of methods and properties that help you trace the execution of your code. This class cannot be inherited.

    (2)Samples:

    The following example uses Trace to indicate the beginning and the end of a program's execution. The example also uses the Trace.Indent and Trace.Unindent methods to distinguish the tracing output. For a more complete example of the use of Trace, see How to: Add Trace Statements to Application Code.

    // Specify /d:TRACE when compiling.
    
    using System;
    using System.Diagnostics;
    
    class Test
    {
        static void Main()
        {
           Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
           Trace.AutoFlush = true;
           Trace.Indent();
           Trace.WriteLine("Entering Main");
           Console.WriteLine("Hello World.");
           Trace.WriteLine("Exiting Main"); 
           Trace.Unindent();
        }
    }
  • 相关阅读:
    centos出现“FirewallD is not running”怎么办
    Centos7开放及查看端口
    phpRedis函数使用总结
    如何在Windows的PHPstudy中使用redis
    Redis命令操作详解
    不可不知 DDoS的攻击原理与防御方法
    DDoS 攻击与防御:从原理到实践
    ORM Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous
    PHP常用函数大全500+
    Linux彻底卸载Nginx
  • 原文地址:https://www.cnblogs.com/wang7/p/2517464.html
Copyright © 2011-2022 走看看