Trace 的使用

Listener objects:

1. DefaultTraceListener class

2. TextWriterTraceListener class

3. XmlWriterTraceListener class

4. EventLogTraceListener class

5. DelimitedListTraceListener class

//Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="5">
<listeners>
<add name="DemoListener" type="System.Diagnostics.XmlWriterTraceListener"
initializeData
="output.xml" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>

//Code

 

 

Trace.Listeners.Clear();
XmlWriterTraceListener MyListener 
= new XmlWriterTraceListener (@"C:\output.xml");
Trace.Listeners.Add(MyListener);
Trace.AutoFlush 
= true;
Trace.WriteLine(
"This is a test");

//Code2 

Trace.Listeners.Clear();
EventLogTraceListener MyListener 
= new EventLogTraceListener ("Chapter10");
Trace.Listeners.Add(MyListener);
Trace.AutoFlush 
= true;
Trace.WriteLine(
"Something happened");

 

更多更详细的描述:

http://www.cnblogs.com/Diwore/archive/2008/10/15/1311321.html

 

posted on 2009-06-05 15:42  博览潇湘  阅读(288)  评论(0编辑  收藏  举报

导航