2010-09-29 17 views
5

Tôi đang cố gắng thiết lập truy tìm .NET. Tôi có thể truy tìm cơ bản để làm việc thông qua System.Diagnostics.Trace, nhưng vì những lý do phức tạp, tôi phải kích hoạt truy tìm thông qua các đối tượng System.Diagnostics.TraceSource (cách mới để thực hiện nó, kể từ .NET 2.0) thay vì sử dụng System .Diagnostics.Trace. Tôi đã thử tất cả mọi thứ nhưng nó chỉ không muốn làm việc bằng cách sử dụng TraceSource. Tôi đang thực hiện truy tìm trong một code-behind ASP.NET (aspx.cs)Truy tìm .NET không hoạt động với Diagnostics.TraceSource, chỉ Diagnostics.Trace

Dưới đây là một số URL liên quan:

http://msdn.microsoft.com/en-us/library/ty48b824.aspx
http://msdn.microsoft.com/en-us/library/64yxa344.aspx
http://msdn.microsoft.com/en-us/library/sk36c28t.aspx
http://blogs.msdn.com/b/bclteam/archive/2005/03/15/396431.aspx
http://msdn.microsoft.com/en-us/library/b0ectfxd%28v=VS.100%29.aspx

Hiện nay , dựa trên những gì có trong web.config, nó phải truy tìm cả tệp và trang, từ mã này:

TraceSource ts = new TraceSource("mysource", SourceLevels.All); 
Trace.Write("Trace (old way)"); // this one works 
ts.TraceInformation("Trace (new way)"); // this one doesn't work 
ts.Flush(); 
ts.Close(); 

Dưới đây là các phần web.config có liên quan:

<system.diagnostics> 
     <trace autoflush="false"> 
      <listeners> <!-- these listeners activate the "old way" of tracing. --> 
       <add  name="pagelistener" /> 
       <add  name="filelistener" /> 
      </listeners> 
     </trace> 

     <sources> 
      <source name="mysource" switchName="myswitch"> 
       <listeners> <!-- these listeners activate the "new way" --> 
         <add name="pagelistener" /> 
         <add name="filelistener" /> 
       </listeners> 
      </source> 
     </sources> 


     <sharedListeners> 
      <!-- these are the actual trace listeners --> 
      <add 
        name="filelistener" 
       type="System.Diagnostics.TextWriterTraceListener" 
       initializeData="loplog.txt" 
       /> 
      <add 
       name="pagelistener" 
       traceOutputOptions="none" 
       type="System.Web.WebPageTraceListener, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
       /> 
     </sharedListeners> 

     <switches> 
      <!-- the sources above use this verbose switch --> 
      <add name="myswitch" value="Verbose"/> 
     </switches> 

</system.diagnostics> 
<system.codedom> 
     <!-- this compilers section should not be needed because I added 
       #define TRACE to the .aspx.cs file, however I put this in 
       since it's still not working. --> 

     <compilers> 
      <compiler 
          language="c#;cs;csharp" 
          extension=".cs" 
          compilerOptions="/d:TRACE" 
          type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
          warningLevel="1" 
          /> 
     </compilers> 
</system.codedom> 

<system.web> 
     <!-- this trace tag should be redundant because I added trace="true" to the aspx file, 
       but I put it in here anyway because this wasn't working. --> 
     <trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="true" requestLimit="50" localOnly="true"/> 

Trả lời

5

thay đổi switchName="mySwitch"-switchValue="Verbose". Điều này sau đó kết quả đầu ra TẤT CẢ dấu vết thông qua tracesource. Bạn có thể thay đổi switchLevel để tăng/giảm độ dài của truy tìm. Trong mẫu của bạn, bạn đã truy tìm một thông báo thông tin, có, tiết, thông tin, cảnh báo, lỗi, quan trọng. Đặt chuyển sang cảnh báo và bạn sẽ không nhận được bất kỳ thông báo chi tiết hoặc thông tin nào.

+0

Tôi đang gặp sự cố tương tự này ngay bây giờ. Điều này dường như không có bất kỳ ảnh hưởng nào đối với tôi. – Josh

Các vấn đề liên quan