You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by bo...@apache.org on 2013/10/10 20:55:19 UTC
svn commit: r1531076 - in /logging/log4net/trunk/src: Core/StackFrameItem.cs
Util/ThreadContextProperties.cs
Author: bodewig
Date: Thu Oct 10 18:55:19 2013
New Revision: 1531076
URL: http://svn.apache.org/r1531076
Log:
LOG4NET-399 doesn't build on CF 2.0
Modified:
logging/log4net/trunk/src/Core/StackFrameItem.cs
logging/log4net/trunk/src/Util/ThreadContextProperties.cs
Modified: logging/log4net/trunk/src/Core/StackFrameItem.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Core/StackFrameItem.cs?rev=1531076&r1=1531075&r2=1531076&view=diff
==============================================================================
--- logging/log4net/trunk/src/Core/StackFrameItem.cs (original)
+++ logging/log4net/trunk/src/Core/StackFrameItem.cs Thu Oct 10 18:55:19 2013
@@ -1,3 +1,4 @@
+#if !NETCF
#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
@@ -29,9 +30,7 @@ namespace log4net.Core
/// as that would require that the containing assembly is loaded.
/// </summary>
///
-#if !NETCF
[Serializable]
-#endif
public class StackFrameItem
{
#region Public Instance Constructors
@@ -194,3 +193,4 @@ namespace log4net.Core
#endregion Private Static Fields
}
}
+#endif
Modified: logging/log4net/trunk/src/Util/ThreadContextProperties.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Util/ThreadContextProperties.cs?rev=1531076&r1=1531075&r2=1531076&view=diff
==============================================================================
--- logging/log4net/trunk/src/Util/ThreadContextProperties.cs (original)
+++ logging/log4net/trunk/src/Util/ThreadContextProperties.cs Thu Oct 10 18:55:19 2013
@@ -18,6 +18,9 @@
#endregion
using System;
+#if NETCF
+using System.Collections;
+#endif
namespace log4net.Util
{
@@ -35,11 +38,18 @@ namespace log4net.Util
{
#region Private Instance Fields
+#if NETCF
+ /// <summary>
+ /// The thread local data slot to use to store a PropertiesDictionary.
+ /// </summary>
+ private readonly static LocalDataStoreSlot s_threadLocalSlot = System.Threading.Thread.AllocateDataSlot();
+#else
/// <summary>
/// Each thread will automatically have its instance.
/// </summary>
[ThreadStatic]
private static PropertiesDictionary _dictionary;
+#endif
#endregion Private Instance Fields
@@ -76,6 +86,9 @@ namespace log4net.Util
{
get
{
+#if NETCF
+ PropertiesDictionary _dictionary = GetProperties(false);
+#endif
if (_dictionary != null)
{
return _dictionary[key];
@@ -84,11 +97,7 @@ namespace log4net.Util
}
set
{
- if (_dictionary == null)
- {
- _dictionary = new PropertiesDictionary();
- }
- _dictionary[key] = value;
+ GetProperties(true)[key] = value;
}
}
@@ -107,6 +116,9 @@ namespace log4net.Util
/// </remarks>
public void Remove(string key)
{
+#if NETCF
+ PropertiesDictionary _dictionary = GetProperties(false);
+#endif
if (_dictionary != null)
{
_dictionary.Remove(key);
@@ -122,6 +134,9 @@ namespace log4net.Util
/// <returns>a set of the defined keys</returns>
public string[] GetKeys()
{
+#if NETCF
+ PropertiesDictionary _dictionary = GetProperties(false);
+#endif
if (_dictionary != null)
{
return _dictionary.GetKeys();
@@ -139,6 +154,9 @@ namespace log4net.Util
/// </remarks>
public void Clear()
{
+#if NETCF
+ PropertiesDictionary _dictionary = GetProperties(false);
+#endif
if (_dictionary != null)
{
_dictionary.Clear();
@@ -163,9 +181,15 @@ namespace log4net.Util
/// </remarks>
internal PropertiesDictionary GetProperties(bool create)
{
- if (_dictionary != null && create)
- {
- return new PropertiesDictionary(_dictionary);
+#if NETCF
+ PropertiesDictionary _dictionary = (PropertiesDictionary)System.Threading.Thread.GetData(s_threadLocalSlot);
+#endif
+ if (_dictionary == null && create)
+ {
+ _dictionary = new PropertiesDictionary();
+#if NETCF
+ System.Threading.Thread.SetData(s_threadLocalSlot, _dictionary);
+#endif
}
return _dictionary;
}
Re: svn commit: r1531076 - in /logging/log4net/trunk/src: Core/StackFrameItem.cs Util/ThreadContextProperties.cs
Posted by Stefan Bodewig <bo...@apache.org>.
On 2013-10-10, <bo...@apache.org> wrote:
> Modified: logging/log4net/trunk/src/Util/ThreadContextProperties.cs
> URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Util/ThreadContextProperties.cs?rev=1531076&r1=1531075&r2=1531076&view=diff
> ==============================================================================
> --- logging/log4net/trunk/src/Util/ThreadContextProperties.cs (original)
>>>> logging/log4net/trunk/src/Util/ThreadContextProperties.cs Thu Oct 10 18:55:19 2013
> internal PropertiesDictionary GetProperties(bool create)
> {
> - if (_dictionary != null && create)
> - {
> - return new PropertiesDictionary(_dictionary);
> + #if NETCF
> + PropertiesDictionary _dictionary = (PropertiesDictionary)System.Threading.Thread.GetData(s_threadLocalSlot);
> + #endif
> + if (_dictionary == null && create)
> + {
Note I've modified the meaning of GetProperties(true) here and brought
it back in line with what the documentation says (and back to what
1.2.11 did).
When _dictionary was null, the method used to create a new dictionary
but in 1.2.12 returns null - I think this is a bug. OTOH if it was not
null then 1.2.12 returned a new dictionary instance in the create ==
true case - now it will always return the existing one.
This doesn't really matter, though, as the method is internal and no
code ever invoked GetProperties(true) in 1.2.12 - at least that's what
grep says.
Stefa