Recently i had some log4net configuration trouble
log4net has a feature in its configuration file where it tries to read Configuration name tags from the config file and locates them as writable properties on the class (Logger/Appender etc..) using reflection.
the function used is
protected void log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElementelement,objecttarget)
this function locates the property for you and updates its data if it finds it if not it fills your screen and logs with garbage until its fixed!
It will even locate the property if you write it in the wrong case.
However, it does not help you in locating your error. I do not expect log4net developers to write a “google-style” {did you mean xxx} function. But I think they could have a better log response
instead of a bland
LogLog.Error(declaringType, "XmlHierarchyConfigurator: Cannot find Property [" + name + "] to set object on [" + target.ToString() + "]");
It would be nicer (I think) to write something like
LogLog.Error(declaringType,
string.Format(
"{2}Reflection did not find Writeable Property/Field named [{0}]. Check ObjectBrowser for class {1} and see what writable attributes/fields exist. maybe misspelled? You XML Error is located in {3}"
, name, target.ToString(), "XmlHierarchyConfigurator", element.ParentNode.InnerXml)
);
which would give something like
XmlHierarchyConfiguratorReflection did not find Writeable Property/Field named [hello]. Check ObjectBrowser for object log4net.Repository.Hierarchy.DefaultLoggerFactory+LoggerImpl and see what writable attributes/fields exist. maybe misspelled? You XML Error is located in <level value=\"Info\" /><hello value=\"4\" /><appender-ref ref=\"LogFileAppender\" /><appender-ref ref=\"RSLogFileAppenderInfo\" /><appender-ref ref=\"RSLogFileAppenderFatal\" />"
for the error of adding the field “hello” to the XML.
This is at the very least a more helpful comment.
At least now I know what to look for. any attribute in log4nt configuration must have a real writeable field/property in the log4net object hierarchy.
good to know.
Mickey Perlstein