protected virtual void OnLoggerRepositoryCreatedEvent()

in src/log4net/Core/DefaultRepositorySelector.cs [472:537]


  protected virtual void OnLoggerRepositoryCreatedEvent(ILoggerRepository repository) 
    => LoggerRepositoryCreatedEvent?.Invoke(this, new(repository));

  /// <summary>
  /// Gets the repository name and repository type for the specified assembly.
  /// </summary>
  /// <param name="assembly">The assembly that has a <see cref="RepositoryAttribute"/>.</param>
  /// <param name="repositoryName">in/out param to hold the repository name to use for the assembly, caller should set this to the default value before calling.</param>
  /// <param name="repositoryType">in/out param to hold the type of the repository to create for the assembly, caller should set this to the default value before calling.</param>
  /// <exception cref="ArgumentNullException"><paramref name="assembly" /> is <see langword="null" />.</exception>
  private void GetInfoForAssembly(Assembly assembly, ref string repositoryName, ref Type repositoryType)
  {
    assembly.EnsureNotNull();

    try
    {
      LogLog.Debug(_declaringType, $"Assembly [{assembly.FullName}] Loaded From [{SystemInfo.AssemblyLocationInfo(assembly)}]");
    }
    catch (Exception e) when (!e.IsFatal())
    {
      // Ignore exception from debug call
    }

    try
    {
      // Look for the RepositoryAttribute on the assembly 
      object[] repositoryAttributes = Attribute.GetCustomAttributes(assembly, typeof(RepositoryAttribute), false);
      if (repositoryAttributes.Length == 0)
      {
        // This is not a problem, but it's nice to know what is going on.
        LogLog.Debug(_declaringType, $"Assembly [{assembly}] does not have a {nameof(RepositoryAttribute)} specified.");
      }
      else
      {
        if (repositoryAttributes.Length > 1)
        {
          LogLog.Error(_declaringType, $"Assembly [{assembly}] has multiple log4net.Config.RepositoryAttribute assembly attributes. Only using first occurrence.");
        }

        RepositoryAttribute domAttr = (RepositoryAttribute)repositoryAttributes[0];
        // If the Name property is set then override the default
        if (domAttr.Name is not null)
        {
          repositoryName = domAttr.Name;
        }

        // If the RepositoryType property is set then override the default
        if (domAttr.RepositoryType is not 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 e) when (!e.IsFatal())
    {
      LogLog.Error(_declaringType, "Unhandled exception in GetInfoForAssembly", e);
    }
  }