in src/log4net/Core/DefaultRepositorySelector.cs [360:431]
public ILoggerRepository CreateRepository(string repositoryName, Type repositoryType)
{
if (repositoryName == null)
{
throw new ArgumentNullException("repositoryName");
}
// If the type is not set then use the default type
if (repositoryType == null)
{
repositoryType = m_defaultRepositoryType;
}
lock(this)
{
ILoggerRepository rep = null;
// First check that the repository does not exist
rep = m_name2repositoryMap[repositoryName] as ILoggerRepository;
if (rep != null)
{
throw new LogException("Repository [" + repositoryName + "] is already defined. Repositories cannot be redefined.");
}
else
{
// Lookup an alias before trying to create the new repository
ILoggerRepository aliasedRepository = m_alias2repositoryMap[repositoryName] as ILoggerRepository;
if (aliasedRepository != null)
{
// Found an alias
// Check repository type
if (aliasedRepository.GetType() == repositoryType)
{
// Repository type is compatible
LogLog.Debug(declaringType, "Aliasing repository [" + repositoryName + "] to existing repository [" + aliasedRepository.Name + "]");
rep = aliasedRepository;
// Store in map
m_name2repositoryMap[repositoryName] = rep;
}
else
{
// Invalid repository type for alias
LogLog.Error(declaringType, "Failed to alias repository [" + repositoryName + "] to existing repository ["+aliasedRepository.Name+"]. Requested repository type ["+repositoryType.FullName+"] is not compatible with existing type [" + aliasedRepository.GetType().FullName + "]");
// We now drop through to create the repository without aliasing
}
}
// If we could not find an alias
if (rep == null)
{
LogLog.Debug(declaringType, "Creating repository [" + repositoryName + "] using type [" + repositoryType + "]");
// Call the no arg constructor for the repositoryType
rep = (ILoggerRepository)Activator.CreateInstance(repositoryType);
// Set the name of the repository
rep.Name = repositoryName;
// Store in map
m_name2repositoryMap[repositoryName] = rep;
// Notify listeners that the repository has been created
OnLoggerRepositoryCreatedEvent(rep);
}
}
return rep;
}
}