1.配置文件
View Code
1 <system.diagnostics>
2 <sources>
3 <source name="TraceError" switchValue="Error,ActivityTracing,Information">
4 <listeners>
5
6 <add initializeData="./clog.txt" type="System.Diagnostics.TextWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
7 name="txtListener" traceOutputOptions="DateTime,ProcessId,ThreadId" >
8 <filter type="System.Diagnostics.EventTypeFilter" initializeData="Error,Information" />
9 </add>
10 </listeners>
11 </source>
12 </sources>
13 <trace autoflush="true">
14 </trace>
15 </system.diagnostics>
2.实例化TraceSource
View Code
1 public TraceSource _ts = new TraceSource("TraceError");
3.在需要记录日志的地方这样写
View Code
1 _ts.TraceData(TraceEventType.Information, 0, Message);