in src/log4net/Config/XmlConfigurator.cs [564:620]
private static void InternalConfigure(ILoggerRepository repository, Stream? configStream)
{
LogLog.Debug(_declaringType, $"configuring repository [{repository.Name}] using stream");
if (configStream is null)
{
LogLog.Error(_declaringType, "Configure called with null 'configStream' parameter");
}
else
{
// Load the config file into a document
XmlDocument? doc = new() { XmlResolver = null };
try
{
// Allow the DTD to specify entity includes
XmlReaderSettings settings = new()
{
// .NET 4.0 warning CS0618: 'System.Xml.XmlReaderSettings.ProhibitDtd'
// is obsolete: 'Use XmlReaderSettings.DtdProcessing property instead.'
DtdProcessing = DtdProcessing.Ignore
};
// Create a reader over the input stream
using XmlReader xmlReader = XmlReader.Create(configStream, settings);
// load the data into the document
doc.Load(xmlReader);
}
catch (Exception e) when (!e.IsFatal())
{
LogLog.Error(_declaringType, "Error while loading XML configuration", e);
// The document is invalid
doc = null;
}
if (doc is not null)
{
LogLog.Debug(_declaringType, "loading XML configuration");
// Configure using the 'log4net' element
XmlNodeList configNodeList = doc.GetElementsByTagName("log4net");
if (configNodeList.Count == 0)
{
LogLog.Debug(_declaringType, "XML configuration does not contain a <log4net> element. Configuration Aborted.");
}
else if (configNodeList.Count > 1)
{
LogLog.Error(_declaringType, $"XML configuration contains [{configNodeList.Count}] <log4net> elements. Only one is allowed. Configuration Aborted.");
}
else
{
InternalConfigureFromXml(repository, configNodeList[0] as XmlElement);
}
}
}
}