Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 3rd, 2008, 08:07 PM
Newbie
 
Join Date: Sep 2008
Posts: 1
Default Tracing with TraceSource to Output (Console Window)

One of the features offered by .NET 2.0 is the use of the TraceSource class. In an attempt to demonstrate its use, I wanted to run my test under the following conditions:

1. Use TraceSource class (Not Trace or Debug classes)

2. Set up the trace solution in the application's application.config file

3. Use Visual Basic.NET to test the trace

4. Test the TraceSource using Visual Studio.NET 2005 IDE "Windows application" rather than with a "Console application"

5. Use "Verbose" level

6. Direct all trace messages to the IDE's Output (Console Window)

7. I wanted to first test the traceSource solution using Visual Basic.NET before attempting it with C#.

---------------------

Config File Content:


Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="TestApp"
       switchName="sourceSwitch"
       switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="console"
           type="System.Diagnostics.ConsoleTraceListener">
          </add>
          <remove name="Default"/>
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="sourceSwitch" value="Verbose"/>
    </switches>
  </system.diagnostics>
</configuration>

Simple Source Code:

Code:
Imports System.Diagnostics

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        method1()
        method2()
        method3()
    End Sub

    Private Sub method1()
        Console.WriteLine("Inside Method1")
    End Sub


    Private Sub method2()
        Console.WriteLine("Inside Method2")
    End Sub


    Private Sub method3()
        Console.WriteLine("Inside Method3")
    End Sub

End Class
---------------------

At issue:

I Wanted to see autogenerated trace events identifying each method call in my application as they were being processed. I assume that Trace Level "Verbose " will show this, however,I do not see any trace statements in the Output window. I see the Console.Writeline statements that I've inserted, but I do not see anything generated by the TraceSource setup. Am I assuming too much from Tracesource? I believe that I was also suppose to add a #define TRACE preprocessor directive (for C#) at the beginning of my source code to turn Tracking on, however, I'm not sure how/where to do the same with Visual Basic.NET.

Thank you,

Mark
Reply
  #2  
Old October 6th, 2008, 12:04 AM
Newbie
 
Join Date: Oct 2008
Posts: 1
Default

Hi mquincey,

You may have already solved your issue, but I faced the same thing. Change the ConsoleTraceListener to DefaultTraceListener. You'll now see your messages in the output window.

I'm not sure why the Console listener does not have the same effect, it confused me too.

By the way, TraceSources are a fantastic feature. What I've done is have each component assembly use a trace source with the same name as the assembly. Therefore, if I want to just trace one assembly in a production environment, I just have to add the trace source config with the assembly name.
Reply
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles