Seperating Debug and Trace Output

S

Stewart Berman

I want to write trace out to a file instead of the default. If I define a trace listener and add it
to the tracelisteners collection the debug output goes there as well.

I tried:
Private myTextWriterTraceListener As TextWriterTraceListener
myTextWriterTraceListener = New TextWriterTraceListener(System.IO.File.CreateText(Trace.txt")
and then
replaced
Trace.WriteLine(System.Reflection.MethodBase.GetCurrentMethod.Name)
Trace.Flush()
Trace.Indent()
with
my.TextWriterTraceListener.WriteLine(System.Reflection.MethodBase.GetCurrentMethod.Name)
myTextWriterTraceListener.Flush()
myTextWriterTraceListener.Indent()
but the last statement won't compile as Indent is not a method of the TextWriterTraceListener class.

Is there someone to use the Trace class without sharing listeners with the Debug class or do I have
to write a custom class to wrap the TextWriterTraceListener class and add an Indent method?
 
J

Jie Wang [MSFT]

Hi Stewart,

The Trace class and the Debug class internally call a class named
TraceInternal which actually does the real work. So there is no way to stop
Trace and Debug from sharing the same set of listeners.

For the Indent method, you can use the IndentLevel property on the
TraceListener instead. The value of the property is an integer indicating
the number of times that the indent specified by the IndentSize property is
applied.

Hope this helps.

Regards,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Stewart Berman

What is the difference between using <SharedListeners> or <Trace> in the application configuration
to define a trace listener?
 
J

Jie Wang [MSFT]

Adding a listener to the shared listeners collection (<sharedListeners>)
does not make it an active listener. It must still be added to a trace
source or a trace by adding it to the Listeners collection for that trace
element.

However, if you add a listener to the <trace><listeners/></trace>, it will
be active by default. That's the difference.

For an example of <sharedListeners> and how to make it active by
configuration:
http://msdn.microsoft.com/en-us/library/ms229501(VS.80).aspx

Regards,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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