Why should Lock structureHolder in LogWriter Class?

Topics: Logging Application Block
Jan 7, 2010 at 2:25 PM

Hi all,

    I'm studying the sourcecode of the logging application block. I find that structureHolderLock is used to lock structureHolder in LogWtirer Class. Why should lock structureHolder? Is structureHolder shared resource?

      Ron

Jan 8, 2010 at 4:39 AM

The lock is there because the logging block monitors its ConfigurationSource for changes. Those changes may be triggered on a separate thread, and cause the StructureHolder to get torn down and re-built according to the new configuration. This would be rather disastrous if it happened during a logging operation, so we lock while logging so that this won't happen.

 

 

Jan 8, 2010 at 5:29 AM

Hi ctavares,

You mean if the ConfigurationSource's logging section is changed, a monitor will find it and this change will cause the StructureHolder to re-built.  the StructureHolder of any LogWriter object is the same reference? And will the changes cause the same StructureHoder objet to re-built?? I looked the sourcecode again, still I don't know why they have the same reference, or they have the same LoggingSetting object?

Ron

Jan 8, 2010 at 9:43 PM

No, the StructureHolders aren't shared across logwriter instances. However, when they're created they get wired up to the configuration source change events.

 

Jan 10, 2010 at 2:48 AM
Edited Jan 10, 2010 at 2:51 AM

Hi ctavares,

Thank you very much, I read sourcecode again and find the LogWriterStructureHolderUpdater class have a eventhandle named "UpdateLogWriter". I guess this is a configuration source change event you said. And the StructureHolder object and the LogWriterStructureHolderUpdater object are both a LogWriter object's private variable. If the ConfigurationSource is changed, the LogWriterStructureHolderUpdater object's method "UpdateLogWriter" will change the StructureHolder object on a separate thread, so you hava to lock it while logging. Am I right?

Ron