Apache log4net™ Manual - Repositories
Logging Repositories
Logging repositories are considered advanced functionality. The default behavior should be sufficient for most users.
Log4net supports logging repositories. A repository is uniquely named. Each repository is a (ILoggerRepository). Multiple assemblies can link to the same repository.
By default there is a single logging repository per process (more precisely per AppDomain). This extends across all assemblies loaded into the process and allows them to all share a single configuration. The configuration of the repository only needs to be done once, typically in the entry point to the application, either programmatically or using a configuration attribute.
Named logging repositories can be created using the LogManager.CreateRepository method. The repository for can be retrieved using the LogManager.GetRepository method. A repository created in this way will need to be configured programmatically.
Attributes
An assembly may choose to utilize a named logging repository rather than the default repository. This completely separates the logging for the assembly from the rest of the application. This can be very useful to component developers that wish to use log4net for their components but do not want to require that all the applications that use their component are aware of log4net. It also means that their debugging configuration is separated from the applications configuration. The assembly should specify the RepositoryAttribute to set its logging repository.
The log4net logging repositories can be configured using the following assembly-level attributes:
-
AliasRepositoryAttribute
Specifies a named repository to use as this assembly's repository.
An assembly's logger repository is defined by its RepositoryAttribute, however this can be overridden by an assembly loaded before the target assembly.
An assembly can alias another assembly's repository by specifying this attribute with the name of the target repository.
This attribute may be used as many times as necessary to alias all the required repositories.
-
RepositoryAttribute
Specifies the logging repository for the assembly.
Assemblies are mapped to logging repositories. This attribute controls the configuration of the repository. The Name property specifies the name of the repository for this assembly. The RepositoryType property specifies the type of the repository object to create for the assembly. If this attribute is not specified and a Name is not specified then the assembly will be part of the default shared logging repository.
This attribute may only be used once per assembly.