TraceListener objects

mike55

Well-known member
Joined
Mar 26, 2004
Messages
726
Location
Ireland
1. XMLWriterTraceListener
2. TextWriterTraceListener
3. DefaultWriterTraceListener

Ok, I am going through the MCTS book for exam 70-536, I am currently looking at chapter 10, lesson 2 "Debugging and Tracing". The lesson talks about using Trace listeners and how they can be implemented using either code or in the .config file.

I have a basic web application, so I have tried to implement the XMLWriterTraceListener in my web.config. I would intend to try out the other 2 listeners also. Now, to apply the changes to the config file only, the following changes need to be made:
Code:
<system.diagnostics>
<trace autoflush="true" indentsize="5">
<listeners>
<add name="xyz" type="System.Diagnostics.XMLWriterTraceListener" initializeData="output.xml"/>
<remove name="Default"/>
</listeners>
</trace>
</system.diagnostics>

The alternative approach is to do the following in code:
Code:
Trace.Listeners.Clear()
Trace.Listeners.Add(New XMLWriterTraceListener("C:\output.xml"))
Trace.Autoflush = True
Trace.WriteLine("This is a Test")

None of the above two code segments worked for me in my web application, for the second code segment, I got an error message: "Listeners is not a member of System.Web.TraceContext".

I then switched my two code segments to a sample windows application. The changes to the app.config coupled with the line:
Code:
Trace.WriteLine("hello world...")
did not appear to work. When I used the second code segment (having removed the changes from the config file), the tracing worked. Have I missed something with regards to the app.config file? Should the changes to the app.config file have worked in my web project?

Mike55.
 
Back
Top