in src/log4net/Config/XmlConfigurator.cs [385:442]
private static void InternalConfigure(ILoggerRepository repository, FileInfo? configFile)
{
LogLog.Debug(_declaringType, $"configuring repository [{repository.Name}] using file [{configFile}]");
if (configFile is null)
{
LogLog.Error(_declaringType, "Configure called with null 'configFile' parameter");
}
else
{
// Have to use File.Exists() rather than configFile.Exists()
// because configFile.Exists() caches the value, not what we want.
if (File.Exists(configFile.FullName))
{
// Open the file for reading
FileStream? fs = null;
// Try hard to open the file
for (int retry = 5; --retry >= 0;)
{
try
{
fs = configFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
break;
}
catch (IOException ex)
{
if (retry == 0)
{
LogLog.Error(_declaringType, $"Failed to open XML config file [{configFile.Name}]", ex);
// The stream cannot be valid
fs = null;
}
Thread.Sleep(250);
}
}
if (fs is not null)
{
try
{
// Load the configuration from the stream
InternalConfigure(repository, fs);
}
finally
{
// Force the file closed whatever happens
fs.Dispose();
}
}
}
else
{
LogLog.Debug(_declaringType, "config file [" + configFile.FullName + "] not found. Configuration unchanged.");
}
}
}