TraceSource记录程序日志

1.配置文件

 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

public TraceSource _ts = new TraceSource("TraceError");


3.在需要记录日志的地方这样写

_ts.TraceData(TraceEventType.Information, 0, Message);

 

posted @ 2014-01-17 11:39  Peter.Luo  阅读(383)  评论(0编辑  收藏  举报