Setting up tracing in config file (windows form app)

D

Daniel Billingsley

The documentation on this subject seems to give you 98% of what you need to
know. From various sources, I have compiled an understanding that this
should work:

<configuration>
<system.diagnostics>
<switches>
<add name="clientswitch" value="3" />
</switches>
<trace autoflush="true" indentsize="0">
<listeners>
<add name="traceListener" type="System.Diagnostics.TextWriterTraceListener,
system version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" initializeData="TraceLog.txt" />
</listeners>
</trace>
</system.diagnostics>
</configuration>

(Pardon the formatting, hard to get it pretty with plain text ya know)

When I execute this line in my code:
Trace.WriteLine("Starting client Form1");
I get a ConfigurationException which says "Couldn't find type for class
System.Diagnostics.TextWriterTraceListener, system version=1.0.5000.0, "
etc. (the whole fqn from the config file is shown).

I can't find an actual fully working example on gotdotnet or msdn, and like
I said the documentation just points you in the general direction but
doesn't really give you the complete answer.

Is there anybody that has this working and can give me some pointers?
 
J

José Joye

The version below works for me. It has the advantage to be .NET version
independant :)

<trace autoflush="true" indentsize="4">
<listeners>
<!-- With the following line, you define the location where the
tracing will
be stored related to the LocalLogSwitch. To disable output,
comment the next line -->
<add name="BTListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\temp\BTFileAcquisition.log" />
<remove type="System.Diagnostics.DefaultTraceListener" />
</listeners>
</trace>

José
 
D

Daniel Billingsley

Thanks that seems to work!

Several sections of the documentation state that the syntax for the listener
includes the fully qualified name, and one section explains how you have to
pull that from the GAC. I've found the .NET doc to be very good, but this
topic needs some work. :)
 
J

José Joye

I more than agree with you!
It took me one year to get the version I have now :-((

José
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top