Hi Stewart,
The Trace class itself and the DefaultTraceListener class are both thread
safe, according to the document (the Thread Safty section):
http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.aspx
http://msdn.microsoft.com/en-us/library/system.diagnostics.defaulttraceliste
ner.aspx
And if you added any non-ThreadSafe listeners to the Trace.Listeners, the
Trace will always use a global lock to ensure thread safety.
The Trace class uses the TraceListener.IsThreadSafe property to determine
if the listener is thread safe.
For my understanding of what you said "In looking at the trace.listeners
collection I noticed that by default there is only one and it is not thread
safe.", yes, the TraceListenerCollection class itself is not guaranteed to
be thread safe, however, that *only* means you don't add/remove listeners
from more than one thread without any protection.
To conclude, for any calls to Trace class itself to log anything, you don't
need to worry about thread safety, the Trace class takes care of it for you
so you can just focus on your task.
If you want to force the Trace class to use a global lock, you can set the
Trace.UseGlobalLock property or write the setting in app.config file:
http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.usegloballo
ck.aspx
Hope this makes it clear.
If you have any further questions, please don't hesitate to let me know.
Thanks,
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.