Results 1 to 2 of 2

Thread: [RESOLVED] [2.0] TraceSource

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Resolved [RESOLVED] [2.0] TraceSource

    I'm trying to learn how use the TraceSource in 2.0 Framework, I have got my custom trace listeners to work correctly however I cannot seems to get the TextWriterTraceListener to work.

    I have tried to initialize the trace listener using the app.config as well as within code.

    Code:
    TraceSource _Source = new TraceSource("Diagnostics", SourceLevels.All);
                TextWriterTraceListener twtl = new TextWriterTraceListener("C:\\myListener.log", "myListener");            
                _Source.Listeners.Add(twtl);
                
                _Source.TraceEvent(TraceEventType.Error, -1, "{0}", "Error");
                _Source.TraceEvent(TraceEventType.Warning, 1, "Warning");
                _Source.TraceEvent(TraceEventType.Verbose, 2, "Verbose");
                _Source.TraceEvent(TraceEventType.Information, 3, "Information");
    or

    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
      </configSections>
      <system.diagnostics>
        <sources>
          <source name="Diagnostics" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch">
            <listeners>                    
              <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\myListener.log" />         
            </listeners>
          </source>
        </sources>
        <switches>
          <add name="sourceSwitch" value="All"/>
        </switches>
      </system.diagnostics>
    </configuration>
    What am I doing incorrectly?

    Thanks

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: [2.0] TraceSource

    I ended up creating my own TextWriterTraceListener which seems to work. I don't know why the Default .NET listener doesn't work.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width