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 2016/10/15 16:08:48 UTC

svn commit: r1765091 - /logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs

Author: bodewig
Date: Sat Oct 15 16:08:48 2016
New Revision: 1765091

URL: http://svn.apache.org/viewvc?rev=1765091&view=rev
Log:
LOG4NET-512 thread-safety fix for Hierarchy

Patch by @JJoe2


Modified:
    logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs

Modified: logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs?rev=1765091&r1=1765090&r2=1765091&view=diff
==============================================================================
--- logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs (original)
+++ logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs Sat Oct 15 16:08:48 2016
@@ -297,7 +297,10 @@ namespace log4net.Repository.Hierarchy
 				throw new ArgumentNullException("name");
 			}
 
-			return m_ht[new LoggerKey(name)] as Logger;
+			lock(m_ht) 
+			{
+				return m_ht[new LoggerKey(name)] as Logger;
+			}
 		}
 
 		/// <summary>
@@ -316,17 +319,20 @@ namespace log4net.Repository.Hierarchy
 			// The accumulation in loggers is necessary because not all elements in
 			// ht are Logger objects as there might be some ProvisionNodes
 			// as well.
-			System.Collections.ArrayList loggers = new System.Collections.ArrayList(m_ht.Count);
-	
-			// Iterate through m_ht values
-			foreach(object node in m_ht.Values)
+			lock(m_ht) 
 			{
-				if (node is Logger) 
+				System.Collections.ArrayList loggers = new System.Collections.ArrayList(m_ht.Count);
+	
+				// Iterate through m_ht values
+				foreach(object node in m_ht.Values)
 				{
-					loggers.Add(node);
+					if (node is Logger) 
+					{
+						loggers.Add(node);
+					}
 				}
+				return (Logger[])loggers.ToArray(typeof(Logger));
 			}
-			return (Logger[])loggers.ToArray(typeof(Logger));
 		}
 
 		/// <summary>
@@ -694,7 +700,10 @@ namespace log4net.Repository.Hierarchy
 		/// </remarks>
 		public void Clear() 
 		{
-			m_ht.Clear();
+			lock(m_ht) 
+			{
+				m_ht.Clear();
+			}
 		}
 
 		/// <summary>