You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by David Thornley <th...@gmail.com> on 2008/02/25 03:27:30 UTC
Possible thread sync issue in XmlLayoutBase:Format()
Hi Everyone,
I ran across a problem with XmlLayoutSchemaLog4j today...
I was getting a NullReferenceException in TextWriterAdapter::Write() after
logging several events from asynchronous socket IO (multiple threads).The
exception failed occured because the internal m_writer of TextWriterAdapter
was null.
The only place I could see m_writer being set to null prior to the
m_protectCloseTextWriter was in XmlLayoutBase::Format() where Attach(null)
is called. So I added a simple lock around the main body of the code in
XmlLayoutBase::Format() using the (m_protectCloseTextWriter) as a sync
object and it fixed the problem. (ie. "lock (m_protectCloseTextWriter)")
I noticed there is synchronisation code in FileAppender::Append(), but I
doubt XmlLayoutBase.Format() is actually atomic. I actually have two
appenders with XmlLayoutSchemaLog4j attached, one is a FileAppender, the
other is a UdpAppender (I suspect that is why).
I'm a noob when it comes to log4net. If anyone with in depth knowledge of
the engine could have a look through the code, and see if there is something
that was missed in the thread synchronisation.
Regards,
David.