Author: rgrabowski Date: Sun Jan 13 10:43:11 2008 New Revision: 611621 URL: http://svn.apache.org/viewvc?rev=611621&view=rev Log: Fix for LOG4NET-31. Allow additional properties to be passed to Converters configured via xml. Moved Hierarchy.PropertyEntry into its own class. Moved PatternString.ConverterInfo into its own class.
Added: logging/log4net/trunk/src/Util/ConverterInfo.cs logging/log4net/trunk/src/Util/PropertyEntry.cs Modified: logging/log4net/trunk/src/Layout/PatternLayout.cs logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs logging/log4net/trunk/src/Util/PatternConverter.cs logging/log4net/trunk/src/Util/PatternParser.cs logging/log4net/trunk/src/Util/PatternString.cs logging/log4net/trunk/src/log4net.vs2005.csproj Modified: logging/log4net/trunk/src/Layout/PatternLayout.cs URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Layout/PatternLayout.cs?rev=611621&r1=611620&r2=611621&view=diff ============================================================================== --- logging/log4net/trunk/src/Layout/PatternLayout.cs (original) +++ logging/log4net/trunk/src/Layout/PatternLayout.cs Sun Jan 13 10:43:11 2008 @@ -965,7 +965,10 @@ // Add all the builtin patterns foreach(DictionaryEntry entry in s_globalRulesRegistry) { - patternParser.PatternConverters[entry.Key] = entry.Value; + ConverterInfo converterInfo = new ConverterInfo(); + converterInfo.Name = (string)entry.Key; + converterInfo.Type = (Type)entry.Value; + patternParser.PatternConverters[entry.Key] = converterInfo; } // Add the instance patterns foreach(DictionaryEntry entry in m_instanceRulesRegistry) @@ -1066,7 +1069,13 @@ /// </remarks> public void AddConverter(ConverterInfo converterInfo) { - AddConverter(converterInfo.Name, converterInfo.Type); + if (converterInfo == null) throw new ArgumentNullException("converterInfo"); + + if (!typeof(PatternConverter).IsAssignableFrom(converterInfo.Type)) + { + throw new ArgumentException("The converter type specified [" + converterInfo.Type + "] must be a subclass of log4net.Util.PatternConverter", "converterInfo"); + } + m_instanceRulesRegistry[converterInfo.Name] = converterInfo; } /// <summary> @@ -1087,66 +1096,14 @@ /// </remarks> public void AddConverter(string name, Type type) { - if (name == null) throw new ArgumentNullException("name"); - if (type == null) throw new ArgumentNullException("type"); + if (name == null) throw new ArgumentNullException("name"); + if (type == null) throw new ArgumentNullException("type"); - if (!typeof(PatternConverter).IsAssignableFrom(type)) - { - throw new ArgumentException("The converter type specified ["+type+"] must be a subclass of log4net.Util.PatternConverter", "type"); - } - m_instanceRulesRegistry[name] = type; - } + ConverterInfo converterInfo = new ConverterInfo(); + converterInfo.Name = name; + converterInfo.Type = type; - /// <summary> - /// Wrapper class used to map converter names to converter types - /// </summary> - /// <remarks> - /// <para> - /// Pattern converter info class used during configuration to - /// pass to the <see cref="PatternLayout.AddConverter(ConverterInfo)"/> - /// method. - /// </para> - /// </remarks> - public sealed class ConverterInfo - { - private string m_name; - private Type m_type; - - /// <summary> - /// default constructor - /// </summary> - public ConverterInfo() - { - } - - /// <summary> - /// Gets or sets the name of the conversion pattern - /// </summary> - /// <remarks> - /// <para> - /// The name of the pattern in the format string - /// </para> - /// </remarks> - public string Name - { - get { return m_name; } - set { m_name = value; } - } - - /// <summary> - /// Gets or sets the type of the converter - /// </summary> - /// <remarks> - /// <para> - /// The value specified must extend the - /// <see cref="PatternConverter"/> type. - /// </para> - /// </remarks> - public Type Type - { - get { return m_type; } - set { m_type = value; } - } + AddConverter(converterInfo); } } } Modified: logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs?rev=611621&r1=611620&r2=611621&view=diff ============================================================================== --- logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs (original) +++ logging/log4net/trunk/src/Repository/Hierarchy/Hierarchy.cs Sun Jan 13 10:43:11 2008 @@ -1027,63 +1027,6 @@ Properties[propertyEntry.Key] = propertyEntry.Value; } - /// <summary> - /// A class to hold the key and data for a property set in the config file - /// </summary> - /// <remarks> - /// <para> - /// A class to hold the key and data for a property set in the config file - /// </para> - /// </remarks> - internal class PropertyEntry - { - private string m_key = null; - private object m_value = null; - - /// <summary> - /// Property Key - /// </summary> - /// <value> - /// Property Key - /// </value> - /// <remarks> - /// <para> - /// Property Key. - /// </para> - /// </remarks> - public string Key - { - get { return m_key; } - set { m_key = value; } - } - - /// <summary> - /// Property Value - /// </summary> - /// <value> - /// Property Value - /// </value> - /// <remarks> - /// <para> - /// Property Value. - /// </para> - /// </remarks> - public object Value - { - get { return m_value; } - set { m_value = value; } - } - - /// <summary> - /// Override <c>Object.ToString</c> to return sensible debug info - /// </summary> - /// <returns>string info about this object</returns> - public override string ToString() - { - return "PropertyEntry(Key="+m_key+", Value="+m_value+")"; - } - } - #endregion Private Instance Methods #region Private Instance Fields Added: logging/log4net/trunk/src/Util/ConverterInfo.cs URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Util/ConverterInfo.cs?rev=611621&view=auto ============================================================================== --- logging/log4net/trunk/src/Util/ConverterInfo.cs (added) +++ logging/log4net/trunk/src/Util/ConverterInfo.cs Sun Jan 13 10:43:11 2008 @@ -0,0 +1,73 @@ +using System; + +namespace log4net.Util +{ + /// <summary> + /// Wrapper class used to map converter names to converter types + /// </summary> + /// <remarks> + /// <para> + /// Pattern converter info class used during configuration by custom + /// PatternString and PatternLayer converters. + /// </para> + /// </remarks> + public sealed class ConverterInfo + { + private string m_name; + private Type m_type; + private readonly PropertiesDictionary properties = new PropertiesDictionary(); + + /// <summary> + /// default constructor + /// </summary> + public ConverterInfo() + { + } + + /// <summary> + /// Gets or sets the name of the conversion pattern + /// </summary> + /// <remarks> + /// <para> + /// The name of the pattern in the format string + /// </para> + /// </remarks> + public string Name + { + get { return m_name; } + set { m_name = value; } + } + + /// <summary> + /// Gets or sets the type of the converter + /// </summary> + /// <remarks> + /// <para> + /// The value specified must extend the + /// <see cref="PatternConverter"/> type. + /// </para> + /// </remarks> + public Type Type + { + get { return m_type; } + set { m_type = value; } + } + + /// <summary> + /// + /// </summary> + /// <param name="entry"></param> + public void AddProperty(PropertyEntry entry) + { + properties[entry.Key] = entry.Value; + } + + /// <summary> + /// + /// </summary> + public PropertiesDictionary Properties + { + get { return properties; } + } + } +} Modified: logging/log4net/trunk/src/Util/PatternConverter.cs URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Util/PatternConverter.cs?rev=611621&r1=611620&r2=611621&view=diff ============================================================================== --- logging/log4net/trunk/src/Util/PatternConverter.cs (original) +++ logging/log4net/trunk/src/Util/PatternConverter.cs Sun Jan 13 10:43:11 2008 @@ -372,5 +372,16 @@ } #endregion + + private PropertiesDictionary properties; + + /// <summary> + /// + /// </summary> + public PropertiesDictionary Properties + { + get { return properties; } + set { properties = value; } + } } } Modified: logging/log4net/trunk/src/Util/PatternParser.cs URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Util/PatternParser.cs?rev=611621&r1=611620&r2=611621&view=diff ============================================================================== --- logging/log4net/trunk/src/Util/PatternParser.cs (original) +++ logging/log4net/trunk/src/Util/PatternParser.cs Sun Jan 13 10:43:11 2008 @@ -27,6 +27,7 @@ using log4net.Layout; using log4net.Core; using log4net.DateFormatter; +using log4net.Layout.Pattern; using log4net.Util; namespace log4net.Util @@ -324,8 +325,8 @@ LogLog.Debug(declaringType, "Converter ["+converterName+"] Option ["+option+"] Format [min="+formattingInfo.Min+",max="+formattingInfo.Max+",leftAlign="+formattingInfo.LeftAlign+"]"); // Lookup the converter type - Type converterType = (Type)m_patternConverters[converterName]; - if (converterType == null) + ConverterInfo converterInfo = (ConverterInfo)m_patternConverters[converterName]; + if (converterInfo == null) { LogLog.Error(declaringType, "Unknown converter name ["+converterName+"] in conversion pattern."); } @@ -335,19 +336,20 @@ PatternConverter pc = null; try { - pc = (PatternConverter)Activator.CreateInstance(converterType); + pc = (PatternConverter)Activator.CreateInstance(converterInfo.Type); } catch(Exception createInstanceEx) { - LogLog.Error(declaringType, "Failed to create instance of Type ["+converterType.FullName+"] using default constructor. Exception: "+createInstanceEx.ToString()); + LogLog.Error(declaringType, "Failed to create instance of Type [" + converterInfo.Type.FullName + "] using default constructor. Exception: " + createInstanceEx.ToString()); } // formattingInfo variable is an instance variable, occasionally reset // and used over and over again pc.FormattingInfo = formattingInfo; pc.Option = option; + pc.Properties = converterInfo.Properties; - IOptionHandler optionHandler = pc as IOptionHandler; + IOptionHandler optionHandler = pc as IOptionHandler; if (optionHandler != null) { optionHandler.ActivateOptions(); Modified: logging/log4net/trunk/src/Util/PatternString.cs URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Util/PatternString.cs?rev=611621&r1=611620&r2=611621&view=diff ============================================================================== --- logging/log4net/trunk/src/Util/PatternString.cs (original) +++ logging/log4net/trunk/src/Util/PatternString.cs Sun Jan 13 10:43:11 2008 @@ -236,7 +236,7 @@ /// </list> /// <para> /// Additional pattern converters may be registered with a specific <see cref="PatternString"/> - /// instance using <see cref="AddConverter(PatternString.ConverterInfo)"/> or + /// instance using <see cref="AddConverter(ConverterInfo)"/> or /// <see cref="AddConverter(string, Type)" />. /// </para> /// <para> @@ -399,7 +399,10 @@ // Add all the builtin patterns foreach(DictionaryEntry entry in s_globalRulesRegistry) { - patternParser.PatternConverters.Add(entry.Key, entry.Value); + ConverterInfo converterInfo = new ConverterInfo(); + converterInfo.Name = (string)entry.Key; + converterInfo.Type = (Type)entry.Value; + patternParser.PatternConverters.Add(entry.Key, converterInfo); } // Add the instance patterns foreach(DictionaryEntry entry in m_instanceRulesRegistry) @@ -464,7 +467,13 @@ /// </remarks> public void AddConverter(ConverterInfo converterInfo) { - AddConverter(converterInfo.Name, converterInfo.Type); + if (converterInfo == null) throw new ArgumentNullException("converterInfo"); + + if (!typeof(PatternConverter).IsAssignableFrom(converterInfo.Type)) + { + throw new ArgumentException("The converter type specified [" + converterInfo.Type + "] must be a subclass of log4net.Util.PatternConverter", "converterInfo"); + } + m_instanceRulesRegistry[converterInfo.Name] = converterInfo; } /// <summary> @@ -482,66 +491,11 @@ if (name == null) throw new ArgumentNullException("name"); if (type == null) throw new ArgumentNullException("type"); - if (!typeof(PatternConverter).IsAssignableFrom(type)) - { - throw new ArgumentException("The converter type specified ["+type+"] must be a subclass of log4net.Util.PatternConverter", "type"); - } - m_instanceRulesRegistry[name] = type; - } - - /// <summary> - /// Wrapper class used to map converter names to converter types - /// </summary> - /// <remarks> - /// <para> - /// Wrapper class used to map converter names to converter types - /// </para> - /// </remarks> - public sealed class ConverterInfo - { - private string m_name; - private Type m_type; - - /// <summary> - /// default constructor - /// </summary> - public ConverterInfo() - { - } - - /// <summary> - /// Gets or sets the name of the conversion pattern - /// </summary> - /// <value> - /// The name of the conversion pattern - /// </value> - /// <remarks> - /// <para> - /// Gets or sets the name of the conversion pattern - /// </para> - /// </remarks> - public string Name - { - get { return m_name; } - set { m_name = value; } - } + ConverterInfo converterInfo = new ConverterInfo(); + converterInfo.Name = name; + converterInfo.Type = type; - /// <summary> - /// Gets or sets the type of the converter - /// </summary> - /// <value> - /// The type of the converter - /// </value> - /// <remarks> - /// <para> - /// Gets or sets the type of the converter - /// </para> - /// </remarks> - public Type Type - { - get { return m_type; } - set { m_type = value; } - } + AddConverter(converterInfo); } } } Added: logging/log4net/trunk/src/Util/PropertyEntry.cs URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Util/PropertyEntry.cs?rev=611621&view=auto ============================================================================== --- logging/log4net/trunk/src/Util/PropertyEntry.cs (added) +++ logging/log4net/trunk/src/Util/PropertyEntry.cs Sun Jan 13 10:43:11 2008 @@ -0,0 +1,59 @@ +namespace log4net.Util +{ + /// <summary> + /// A class to hold the key and data for a property set in the config file + /// </summary> + /// <remarks> + /// <para> + /// A class to hold the key and data for a property set in the config file + /// </para> + /// </remarks> + public class PropertyEntry + { + private string m_key = null; + private object m_value = null; + + /// <summary> + /// Property Key + /// </summary> + /// <value> + /// Property Key + /// </value> + /// <remarks> + /// <para> + /// Property Key. + /// </para> + /// </remarks> + public string Key + { + get { return m_key; } + set { m_key = value; } + } + + /// <summary> + /// Property Value + /// </summary> + /// <value> + /// Property Value + /// </value> + /// <remarks> + /// <para> + /// Property Value. + /// </para> + /// </remarks> + public object Value + { + get { return m_value; } + set { m_value = value; } + } + + /// <summary> + /// Override <c>Object.ToString</c> to return sensible debug info + /// </summary> + /// <returns>string info about this object</returns> + public override string ToString() + { + return "PropertyEntry(Key=" + m_key + ", Value=" + m_value + ")"; + } + } +} Modified: logging/log4net/trunk/src/log4net.vs2005.csproj URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/log4net.vs2005.csproj?rev=611621&r1=611620&r2=611621&view=diff ============================================================================== --- logging/log4net/trunk/src/log4net.vs2005.csproj (original) +++ logging/log4net/trunk/src/log4net.vs2005.csproj Sun Jan 13 10:43:11 2008 @@ -543,6 +543,7 @@ <Compile Include="Util\ContextPropertiesBase.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Util\ConverterInfo.cs" /> <Compile Include="Util\CountingQuietTextWriter.cs"> <SubType>Code</SubType> </Compile> @@ -637,6 +638,7 @@ <Compile Include="Util\PropertiesDictionary.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Util\PropertyEntry.cs" /> <Compile Include="Util\ProtectCloseTextWriter.cs"> <SubType>Code</SubType> </Compile>