You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2004/08/19 23:31:09 UTC
cvs commit: logging-log4net/src/Repository/Hierarchy XmlHierarchyConfigurator.cs
nicko 2004/08/19 14:31:09
Modified: src/Repository/Hierarchy XmlHierarchyConfigurator.cs
Log:
Added explicit parameter subtype specification. This allows the subtype of
a property to be specified in the config file allowing an appropriate
converter to be found for the string value. This allows the following to
be specified in the config file:
<layout type="log4net.Layout.PatternLayout" value="%d [%t] %-5p %c [%x] - %m%n" />
This leverages the pattern layout TypeConverter to convert the value into the
required type.
Revision Changes Path
1.8 +29 -0 logging-log4net/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs
Index: XmlHierarchyConfigurator.cs
===================================================================
RCS file: /home/cvs/logging-log4net/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XmlHierarchyConfigurator.cs 30 Jul 2004 17:35:50 -0000 1.7
+++ XmlHierarchyConfigurator.cs 19 Aug 2004 21:31:09 -0000 1.8
@@ -552,6 +552,35 @@
LogLog.Debug("XmlConfigurator: Security exception while trying to expand environment variables. Error Ignored. No Expansion.");
}
#endif
+
+ // Check if a specific subtype is specified on the element using the 'type' attribute
+ string subTypeString = element.GetAttribute(TYPE_ATTR);
+ if (subTypeString != null && subTypeString.Length > 0)
+ {
+ // Read the explicit subtype
+ try
+ {
+ Type subType = SystemInfo.GetTypeFromString(subTypeString, true, true);
+
+ LogLog.Debug("XmlConfigurator: Parameter ["+name+"] specified subtype ["+subType.FullName+"]");
+
+ if (!propertyType.IsAssignableFrom(subType))
+ {
+ LogLog.Error("XmlConfigurator: Subtype ["+subType.FullName+"] set on ["+name+"] is not a subclass of property type ["+propertyType.FullName+"]");
+ }
+ else
+ {
+ // The subtype specified is found and is actually a subtype of the property
+ // type, therefore we can switch to using this type.
+ propertyType = subType;
+ }
+ }
+ catch(Exception ex)
+ {
+ LogLog.Error("XmlConfigurator: Failed to find type ["+subTypeString+"] set on ["+name+"]", ex);
+ }
+ }
+
// Now try to convert the string value to an acceptable type
// to pass to this property.