本文整理汇总了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();
}
}
示例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();
}
}
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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();
}
}
}