2010-09-29 3 views
5

Sto tentando di impostare la traccia .NET. Sono in grado di ottenere l'analisi di base per lavorare tramite System.Diagnostics.Trace, ma per motivi complicati devo attivare la traccia tramite System.Diagnostics.TraceSource objects (il nuovo modo di farlo, da .NET 2.0) piuttosto che usare System .Diagnostics.Trace. Ho provato tutto ma non vuole lavorare usando TraceSource. Sto eseguendo il tracciato in un code-behind ASP.NET (aspx.cs)Traccia .NET non funzionante con Diagnostics.TraceSource, solo Diagnostics.Trace

Ecco alcuni URL correlati:

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

Attualmente , in base a ciò che è in web.config, dovrebbe essere tracciato sia su un file che sulla pagina, da questo codice:

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

Ecco sezioni web.config che sono rilevanti:

<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"/> 

risposta

5

cambiamento switchName="mySwitch"-switchValue="Verbose". Ciò restituisce quindi TUTTE le tracce tramite traceource. È possibile modificare switchLevel per aumentare/ridurre la verbosità della traccia. Nel tuo esempio hai tracciato un messaggio informativo, ci sono, verbose, informazioni, avvertimenti, errori, critici. Imposta l'opzione su avviso e non otterrai alcun messaggio dettagliato o informativo.

+0

Sto avendo lo stesso problema adesso. Questo non sembrava avere alcun effetto per me. – Josh