當前位置: 首頁>>代碼示例>>C#>>正文


C# TextWriterTraceListener構造函數代碼示例

本文整理匯總了C#中System.Diagnostics.TextWriterTraceListener.TextWriterTraceListener構造函數的典型用法代碼示例。如果您正苦於以下問題:C# TextWriterTraceListener構造函數的具體用法?C# TextWriterTraceListener怎麽用?C# TextWriterTraceListener使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在System.Diagnostics.TextWriterTraceListener的用法示例。


在下文中一共展示了TextWriterTraceListener構造函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

public class Sample
{

public static void Main(string[] args) {
    /* Create a text writer that writes to the console screen and add
     * it to the trace listeners */
    TextWriterTraceListener myWriter = new TextWriterTraceListener();
    myWriter.Writer = System.Console.Out;
    Trace.Listeners.Add(myWriter);
 
    // Write the output to the console screen.
    myWriter.Write("Write to the Console screen. ");
    myWriter.WriteLine("Again, write to console screen.");
 
    // Flush and close the output.
    myWriter.Flush();
    myWriter.Close();
 }
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:19,代碼來源:TextWriterTraceListener

示例2: Main

//引入命名空間
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.VisualBasic;

class TWTLConStreamMod
{

    // args(0) is the specification of the trace log file.
    public static void Main(string[] args)
    {

        // Verify that a parameter was entered.
        if (args.Length==0)
        {
            Console.WriteLine("Enter a trace file specification.");
        }
        else
        {
            // Create a stream object.
            FileStream traceStream;
            try
            {
                traceStream = new FileStream(args[0], FileMode.Append, FileAccess.Write);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Error creating FileStream for trace file \"{0}\":" +
                    "\r\n{1}", args[0], ex.Message);
                return;
            }

            // Create a TextWriterTraceListener object that takes a stream.
            TextWriterTraceListener textListener;
            textListener = new TextWriterTraceListener(traceStream);
            Trace.Listeners.Add(textListener);

            // Write these messages only to this TextWriterTraceListener.
            textListener.WriteLine("This is trace listener named \""+ textListener.Name+"\"");
            textListener.WriteLine("Trace written through a stream to: " +
                "\r\n    \""+args[0]+"\"");

            // Write a message to all trace listeners.
            Trace.WriteLine(String.Format("This trace message written {0} to all listeners.", DateTime.Now));

            // Flush and close the output.
            Trace.Flush();
            textListener.Flush();
            textListener.Close();
        }
    }
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:53,代碼來源:TextWriterTraceListener

示例3: Main

#define TRACE

using System;
using System.IO;
using System.Diagnostics;

public class TextWriterTraceListenerSample
{
    public static void Main() 
    {
        TextWriterTraceListener myTextListener = null;

        // Create a file for output named TestFile.txt.
        String myFileName = "TestFile.txt";
        StreamWriter myOutputWriter = new StreamWriter(myFileName, true);

        // Add a TextWriterTraceListener for the file.
        myTextListener = new TextWriterTraceListener(myOutputWriter);
        Trace.Listeners.Add(myTextListener);

        // Write trace output to all trace listeners.
        Trace.WriteLine(DateTime.Now.ToString() + " - Trace output");
 
        // Remove and close the file writer/trace listener.
        myTextListener.Flush();
        Trace.Listeners.Remove(myTextListener);
        myTextListener.Close();
    }
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:29,代碼來源:TextWriterTraceListener

示例4: Main

//引入命名空間
using System;
using System.Diagnostics;
using Microsoft.VisualBasic;

class TWTLConStringMod
{

    // args(0) is the specification of the trace log file.
    public static void Main(string[] args)
    {

        // Verify that a parameter was entered.
        if (args.Length==0)
        {
            Console.WriteLine("Enter a trace file specification.");
        }
        else
        {
            // Create a TextWriterTraceListener object that takes a 
            // file specification.
            TextWriterTraceListener textListener;
            try
            {
                textListener = new TextWriterTraceListener(args[0]);
                Trace.Listeners.Add(textListener);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Error creating TextWriterTraceListener for trace " +
                    "file \"{0}\":\r\n{1}", args[0], ex.Message);
                return;
            }

            // Write these messages only to the TextWriterTraceListener.
            textListener.WriteLine("This is trace listener named \""+textListener.Name+"\"");
            textListener.WriteLine("Trace written to a file: " +
                "\r\n    \""+args[0]+"\"");

            // Write a message to all trace listeners.
            Trace.WriteLine(String.Format("This trace message written {0} to all listeners.", DateTime.Now));

            // Flush and close the output.
            Trace.Flush();
            textListener.Flush();
            textListener.Close();
        }
    }
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:49,代碼來源:TextWriterTraceListener

示例5: Main

//引入命名空間
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.VisualBasic;

class TWTLConStreamNameMod
{

    const string LISTENER_NAME = "myStreamListener";

    // args(0) is the specification of the trace log file.
    public static void Main(string[] args)
    {

        // Verify that a parameter was entered.
        if (args.Length==0)
        {
            Console.WriteLine("Enter a trace file specification.");
        }
        else
        {
            // Create a stream object.
            FileStream traceStream;
            try
            {
                traceStream = new FileStream(args[0], FileMode.Append, FileAccess.Write);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Error creating FileStream for trace file \"{0}\":" +
                    "\r\n{1}", args[0], ex.Message);
                return;
            }

            // Create a TextWriterTraceListener object that takes a stream.
            TextWriterTraceListener textListener;
            textListener = new TextWriterTraceListener(traceStream, LISTENER_NAME);
            Trace.Listeners.Add(textListener);

            // Write these messages only to the TextWriterTraceListener.
            textListener.WriteLine("This is trace listener named \""+textListener.Name+"\"");
            textListener.WriteLine("Trace written through a stream to: " +
                "\r\n    \""+args[0]+"\"");

            // Write a message to all trace listeners.
            Trace.WriteLine(String.Format("This trace message written {0} to all listeners.", DateTime.Now));

            // Flush and close the output.
            Trace.Flush();
            textListener.Flush();
            textListener.Close();
        }
    }
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:55,代碼來源:TextWriterTraceListener

示例6: Main

//引入命名空間
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.VisualBasic;

class TWTLConWriterNameMod
{

    const string LISTENER_NAME = "myWriterListener";

    // args(0) is the specification of the trace log file.
    public static void Main(string[] args)
    {

        // Verify that a parameter was entered.
        if (args.Length==0)
        {
            Console.WriteLine("Enter a trace file specification.");
        }
        else
        {
            // Create a StreamWriter object that supports appending.
            StreamWriter traceWriter;
            try
            {
                traceWriter = new StreamWriter(args[0], true);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Error creating StreamWriter for trace file \"{0}\":" +
                    "\r\n{1}", args[0], ex.Message);
                return;
            }

            // Create a TextWriterTraceListener that takes a StreamWriter.
            TextWriterTraceListener textListener;
            textListener = new TextWriterTraceListener(traceWriter, LISTENER_NAME);
            Trace.Listeners.Add(textListener);

            // Write these messages only to this TextWriterTraceListener.
            textListener.WriteLine("This is trace listener named \""+textListener.Name+"\"");
            textListener.WriteLine("Trace written through a stream to: " +
                "\r\n    \""+args[0]+"\"");

            // Write a message to all trace listeners.
            Trace.WriteLine(String.Format("This trace message written {0} to all listeners.", DateTime.Now));

            // Flush and close the output.
            Trace.Flush();
            textListener.Flush();
            textListener.Close();
        }
    }
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:55,代碼來源:TextWriterTraceListener

示例7: Main

//引入命名空間
using System;
using System.Diagnostics;
using Microsoft.VisualBasic;

class TWTLConStringNameMod
{

    const string LISTENER_NAME = "myStringListener";

    // args(0) is the specification of the trace log file.
    public static void Main(string[] args)
    {

        // Verify that a parameter was entered.
        if (args.Length==0)
        {
            Console.WriteLine("Enter a trace file specification.");
        }
        else
        {
            // Create a TextWriterTraceListener object that takes a 
            // file specification.
            TextWriterTraceListener textListener;
            try
            {
                textListener = new TextWriterTraceListener(args[0], LISTENER_NAME);
                Trace.Listeners.Add(textListener);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Error creating TextWriterTraceListener for trace " +
                    "file \"{0}\":\r\n{1}", args[0], ex.Message);
                return;
            }

            // Write these messages only to this TextWriterTraceListener.
            textListener.WriteLine("This is trace listener named \""+textListener.Name+"\"");
            textListener.WriteLine("Trace written to a file: " +
                "\r\n    \""+args[0]+"\"");

            // Write a message to all trace listeners.
            Trace.WriteLine(String.Format("This trace message written {0} to all listeners.", DateTime.Now));

            // Flush and close the output.
            Trace.Flush();
            textListener.Flush();
            textListener.Close();
        }
    }
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:51,代碼來源:TextWriterTraceListener


注:本文中的System.Diagnostics.TextWriterTraceListener.TextWriterTraceListener構造函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。