Index: src/Util/LogicalThreadContextProperties.cs
===================================================================
--- src/Util/LogicalThreadContextProperties.cs (revision 480010)
+++ src/Util/LogicalThreadContextProperties.cs (working copy)
@@ -96,9 +96,25 @@
return null;
}
set
- {
+ {
// Force the dictionary to be created
- GetProperties(true)[key] = value;
+ PropertiesDictionary dictionary = GetProperties(true);
+
+ // If there is already a value set for this key and it
+ // is different from the value to be set then we
+ // must create a shallow copy of the dictionary to
+ // propagate an independent dictionary with the new value
+ // through the execution code path.
+ if (dictionary[key] != null && dictionary[key] != value)
+ {
+ dictionary = dictionary.Clone() as PropertiesDictionary;
+ dictionary[key] = value;
+ CallContext.SetData("log4net.Util.LogicalThreadContextProperties", dictionary);
+ }
+ else
+ {
+ dictionary[key] = value;
+ }
}
}
Index: src/Util/PropertiesDictionary.cs
===================================================================
--- src/Util/PropertiesDictionary.cs (revision 480010)
+++ src/Util/PropertiesDictionary.cs (working copy)
@@ -21,6 +21,7 @@
#if !NETCF
using System.Runtime.Serialization;
using System.Xml;
+using System.Runtime.Remoting.Messaging;
#endif
namespace log4net.Util
@@ -34,13 +35,25 @@
/// objects that are serializable will
/// be serialized along with this collection.
///
+ ///
+ /// Christian Kihm:
+ ///
+ /// MSDN says that ILogicalThreadAffinative marks an object that can
+ /// propagate outside of an AppDomain in a LogicalCallContext. I have made
+ /// the experience that you also have to mark an object with
+ /// ILogicalThreadAffinative to propagate it outside of the current Thread.
+ ///
+ /// To get LogicalThreadContextProperties to work as expected we must
+ /// implement ILogicalThreadAffinative.
+ ///
///
/// Nicko Cadell
/// Gert Driesen
#if NETCF
public sealed class PropertiesDictionary : ReadOnlyPropertiesDictionary, IDictionary
#else
- [Serializable] public sealed class PropertiesDictionary : ReadOnlyPropertiesDictionary, ISerializable, IDictionary
+ [Serializable]
+ public sealed class PropertiesDictionary : ReadOnlyPropertiesDictionary, ISerializable, IDictionary, ILogicalThreadAffinative, ICloneable
#endif
{
#region Public Instance Constructors
@@ -329,6 +342,18 @@
}
#endregion
+
+ #region ICloneable Members
+
+ ///
+ /// Create a shallow copy
+ ///
+ /// A shallow copy
+ public object Clone()
+ {
+ return new PropertiesDictionary(new ReadOnlyPropertiesDictionary(this));
+ }
+
+ #endregion
}
-}
-
+}
\ No newline at end of file