xml logging and threading

Topics: Logging Application Block
Jun 9, 2010 at 10:18 AM

Hi All

I have been using the xml trace listener. And I am wondering is it thread safe. If not I would prefer not having each thread locked waiting to log. But the logger to do the locking and thread safety for me.

Many thanks

Paul

 

 

Jun 10, 2010 at 8:58 AM

XmlTraceListener class is inheriting its IsThreadSafe property value from System.Diagnostics.TraceListener which is by default value is False (see for more details http://msdn.microsoft.com/en-us/library/ms141033). Meaning the XmlTraceListener is not thread safe.

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 10, 2010 at 11:40 AM

Hi Gino

I have created my own xmltracelistener, can I add IsThreadSafe== true somewhere in my code to ensure that it is safe ? Ops its a property get only. Any thoughts on how to enure it is threadsafe

Many thanks

Paul

 

Jun 10, 2010 at 2:35 PM

Hi Paul,

Yeah you're correct its a get only property so it will not work that way. Anyway, (I know I should have stated this earlier in this thread) I do think the logging block process as a whole, is thread safe. I've tried it in multithread app and so far no issues have encountered, also to give more context, there is actually an issue regarding this that has already been addressed quite a long time ago. You can check this thread http://entlib.codeplex.com/Thread/View.aspx?ThreadId=8360 and workitem http://entlib.codeplex.com/workitem/9592?ProjectName=entlib if you want to.

Though, if you still want to make sure that something like this would not come out suddenly in your application then you can be proactive to add your own locking or wait handles every time you are executing the actual writing/logging. It's kinda look like a bug on the Category Source level filter but I'm still not sure if it is indeed. 

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com