I wasn't able to reproduce the exception you're experiencing but looking at its details and the code of XmlHierarchyConfigurator
class, the exception is thrown when the root xml element name is not log4net
and this is exactly what you're trying to do.
What you can try to do is to:
- Read your custom
log2net
XmlElement
- Create a new
log4net
XmlElement
- Copy all the children of your
log2net
to the newlog4net
element - Execute
XmlConfigurator.Configure()
method passing your newlog4net
element.
XmlElement element = (XmlElement)ConfigurationManager.GetSection("log2net");
XmlElement newLog4net = element.OwnerDocument.CreateElement("log4net");
for (int i = 0; i < element.ChildNodes.Count; i++)
{
XmlNode child = element.ChildNodes[i];
newLog4net.AppendChild(child.CloneNode(true));
}
log4net.Config.XmlConfigurator.Configure(newLog4net);