TraceSource記錄程序日誌

1.配置文件spa

 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.在須要記錄日誌的地方這樣寫code

_ts.TraceData(TraceEventType.Information, 0, Message);
相關文章
相關標籤/搜索