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>
<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");
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");
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