当前位置: 首页>>代码示例>>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;未经允许,请勿转载。