Trace Listener

  • Thread starter Thread starter Jason L James
  • Start date Start date
J

Jason L James

Hi all,

can anyone help me with some tracing I am trying to do
in my application. I have a configuration file containing
the XML as detailed below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="myBooleanSwitch" value="2" />
</switches>
</system.diagnostics>
</configuration>

I have declared a public variable as detailed below:

Public myBooleanSwitch As New BooleanSwitch("myBooleanSwitch",
"Controlss Data Tracing")


However, when I execute the code below, I only appear to insert
the unconditional trace.writeline command, and not the conditional
trace.writelineif command.


Dim myLog As New FileStream("C:\output.txt",
FileMode.OpenOrCreate)
Dim myTrace As New TextWriterTraceListener(myLog)
Trace.Listeners.Add(myTrace)
Trace.AutoFlush = True
Trace.WriteLineIf(myBooleanSwitch.Enabled, "Boolean Switch
Enabled")
Trace.WriteLine("Trace write line")
'Trace.Flush()
Trace.Close()
myLog.Close()
Trace.Listeners.Remove(myTrace)
myTrace.Dispose()
myLog = Nothing


Does anyone have any ideas? I created the configuration file,
called Debug_Trace Listener.config using the IDE (VB.Net). I
have even copied it to the bin folder and the debug folder to make
sure there it can be found.

Many thanks,

Jason.
 
Is this a Windows Forms Application? If so rename the config file to
"App.config" and it should work.

The config file should be in the root source folder of the project if
running from the IDE, or in the folder of the compiled application
otherwise.

Hope this helps.
 
Back
Top