System.Diagnostics.TraceSource

Discussion in 'ASP.NET 2.0' started by Jdrewdials, Nov 8, 2007.

  1. Am I crazy or is this disabled somehow?

    I have this in my config file.



    <system.diagnostics>


    <sources>


    <source name="Errors" switchName="ErrorSwitch" switchType="System.Diagnostics.SourceSwitch">


    <listeners>


    <clear />


    <add name="file" type="System.Diagnostics.XmlWriterTraceListener" initializeData="ErrorLog.xml" traceOutputOptions="DateTime,Callstack"/>


    </listeners>


    </source>


    </sources>


    <switches>


    <add name="ErrorSwitch" value="Warning" />


    </switches> </system.diagnostics>





    And it looks right to me. I don't get any errors. But when I try to use


    System.Diagnostics.TraceSource _errors = new System.Diagnostics.TraceSource("Errors");


    _errors.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, "blah");


    I get nothing. Not even the file itself. Usually, when you have it configured correctly, the file will be created as soon as the AppPool is reloaded. If you don't have it configured correctly, it will throw an error. I get neither of these....


    Am I doing something stupid or is this disabled? I've seen that we can write to the file system, so I wouldn't think this would be a problem. if it is, could we at least use a trace listener that logs to sql server?


    Thanks, Drew
     
  2. I haven't messed with this but...
    At leasta fewthings do look odd;

    If you're working with an XML files shouldn't add name= be xml instead of file?
    <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData=. . .

    Shouldn't there be a trace section in that?
    <trace autoflush="false" />
    or...
    <trace autoflush="true" />

    Did you import the System.Diagnostics namespace in the page?
     
  3. Good point. in my snippet that I put on the message board, I inadvertently left off the <trace> portion of the config file because it looks like this



    <trace autoflush="true">


    <listeners>


    <clear />


    <add name="whocares" type="System.Diagnostics.TextWriterTraceListener" initializeData="test.txt"/>


    </listeners>


    </trace>


    I was trying to just do a straight output with no sources or switches and it still didn't work, but it does contain my flush settings (that's gotten me too many times to count).


    The name shouldn't matter at all since I'm adding it directly to the listners collection. The only time the name should matter is if I'm putting it into shared listeners and then referencing it from my TraceSource.
     
  4. I too was having the same problem while playing around with the System.Diagnostics tracing. But what I forgot to do was enable the TRACE switch in the compiler options. Only then will anything be written. Put this in your web.config:

     
  5. You rock!
     

Share This Page