in src/log4net/Core/DefaultRepositorySelector.cs [571:641]
private void GetInfoForAssembly(Assembly assembly, ref string repositoryName, ref Type repositoryType)
{
if (assembly == null)
{
throw new ArgumentNullException("assembly");
}
try
{
LogLog.Debug(declaringType, "Assembly [" + assembly.FullName + "] Loaded From [" + SystemInfo.AssemblyLocationInfo(assembly) + "]");
}
catch
{
// Ignore exception from debug call
}
try
{
// Look for the RepositoryAttribute on the assembly
#if NETSTANDARD
object[] repositoryAttributes = assembly.GetCustomAttributes(typeof(log4net.Config.RepositoryAttribute)).ToArray();
#else
object[] repositoryAttributes = Attribute.GetCustomAttributes(assembly, typeof(log4net.Config.RepositoryAttribute), false);
#endif
if (repositoryAttributes == null || repositoryAttributes.Length == 0)
{
// This is not a problem, but its nice to know what is going on.
LogLog.Debug(declaringType, "Assembly [" + assembly + "] does not have a RepositoryAttribute specified.");
}
else
{
if (repositoryAttributes.Length > 1)
{
LogLog.Error(declaringType, "Assembly [" + assembly + "] has multiple log4net.Config.RepositoryAttribute assembly attributes. Only using first occurrence.");
}
log4net.Config.RepositoryAttribute domAttr = repositoryAttributes[0] as log4net.Config.RepositoryAttribute;
if (domAttr == null)
{
LogLog.Error(declaringType, "Assembly [" + assembly + "] has a RepositoryAttribute but it does not!.");
}
else
{
// If the Name property is set then override the default
if (domAttr.Name != null)
{
repositoryName = domAttr.Name;
}
// If the RepositoryType property is set then override the default
if (domAttr.RepositoryType != null)
{
// Check that the type is a repository
if (typeof(ILoggerRepository).IsAssignableFrom(domAttr.RepositoryType))
{
repositoryType = domAttr.RepositoryType;
}
else
{
LogLog.Error(declaringType, "DefaultRepositorySelector: Repository Type [" + domAttr.RepositoryType + "] must implement the ILoggerRepository interface.");
}
}
}
}
}
catch (Exception ex)
{
LogLog.Error(declaringType, "Unhandled exception in GetInfoForAssembly", ex);
}
}