Class LoggerManager
Static manager that controls the creation of repositories
public sealed class LoggerManager
- Inheritance
-
LoggerManager
- Inherited Members
Remarks
Static manager that controls the creation of repositories
This class is used by the wrapper managers (e.g. LogManager) to provide access to the ILogger objects.
This manager also holds the IRepositorySelector that is used to
lookup and create repositories. The selector can be set either programmatically using
the RepositorySelector property, or by setting the log4net.RepositorySelector
AppSetting in the applications config file to the fully qualified type name of the
selector to use.
Properties
RepositorySelector
Gets or sets the repository selector used by the LogManager.
public static IRepositorySelector RepositorySelector { get; set; }
Property Value
- IRepositorySelector
The repository selector used by the LogManager.
Remarks
The repository selector (IRepositorySelector) is used by the LogManager to create and select repositories (ILoggerRepository).
The caller to LogManager supplies either a string name or an assembly (if not supplied the assembly is inferred using Assembly.GetCallingAssembly()).
This context is used by the selector to lookup a specific repository.
For the full .NET Framework, the default repository is DefaultRepositorySelector;
for the .NET Compact Framework CompactRepositorySelector is the default
repository.
Methods
CreateDomain(Assembly, Type)
Creates a repository for the specified assembly and repository type.
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(Assembly repositoryAssembly, Type repositoryType)
Parameters
repositoryAssemblyAssemblyThe assembly to use to get the name of the repository.
repositoryTypeTypeA Type that implements ILoggerRepository and has a no arg constructor. An instance of this type will be created to act as the ILoggerRepository for the repository specified.
Returns
- ILoggerRepository
The ILoggerRepository created for the repository.
Remarks
CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.
The ILoggerRepository created will be associated with the repository specified such that a call to GetRepository(Assembly) with the same assembly specified will return the same repository instance.
CreateDomain(string)
Creates a repository with the specified name.
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(string repository)
Parameters
repositorystringThe name of the repository, this must be unique amongst repositories.
Returns
- ILoggerRepository
The ILoggerRepository created for the repository.
Remarks
CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.
Creates the default type of ILoggerRepository which is a Hierarchy object.
The repository name must be unique. Repositories cannot be redefined.
An Exception will be thrown if the repository already exists.
Exceptions
- LogException
The specified repository already exists.
CreateDomain(string, Type)
Creates a repository with the specified name and repository type.
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(string repository, Type repositoryType)
Parameters
repositorystringThe name of the repository, this must be unique to the repository.
repositoryTypeTypeA Type that implements ILoggerRepository and has a no arg constructor. An instance of this type will be created to act as the ILoggerRepository for the repository specified.
Returns
- ILoggerRepository
The ILoggerRepository created for the repository.
Remarks
CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.
The repository name must be unique. Repositories cannot be redefined.
An Exception will be thrown if the repository already exists.
Exceptions
- LogException
The specified repository already exists.
CreateRepository(Assembly, Type)
Creates a repository for the specified assembly and repository type.
public static ILoggerRepository CreateRepository(Assembly repositoryAssembly, Type repositoryType)
Parameters
repositoryAssemblyAssemblyThe assembly to use to get the name of the repository.
repositoryTypeTypeA Type that implements ILoggerRepository and has a no arg constructor. An instance of this type will be created to act as the ILoggerRepository for the repository specified.
Returns
- ILoggerRepository
The ILoggerRepository created for the repository.
Remarks
The ILoggerRepository created will be associated with the repository specified such that a call to GetRepository(Assembly) with the same assembly specified will return the same repository instance.
CreateRepository(string)
Creates a repository with the specified name.
public static ILoggerRepository CreateRepository(string repository)
Parameters
repositorystringThe name of the repository, this must be unique amongst repositories.
Returns
- ILoggerRepository
The ILoggerRepository created for the repository.
Remarks
Creates the default type of ILoggerRepository which is a Hierarchy object.
The repository name must be unique. Repositories cannot be redefined.
An Exception will be thrown if the repository already exists.
Exceptions
- LogException
The specified repository already exists.
CreateRepository(string, Type)
Creates a repository with the specified name and repository type.
public static ILoggerRepository CreateRepository(string repository, Type repositoryType)
Parameters
repositorystringThe name of the repository, this must be unique to the repository.
repositoryTypeTypeA Type that implements ILoggerRepository and has a no arg constructor. An instance of this type will be created to act as the ILoggerRepository for the repository specified.
Returns
- ILoggerRepository
The ILoggerRepository created for the repository.
Remarks
The repository name must be unique. Repositories cannot be redefined.
An Exception will be thrown if the repository already exists.
Exceptions
- LogException
The specified repository already exists.
Exists(Assembly, string)
Returns the named logger if it exists.
public static ILogger Exists(Assembly repositoryAssembly, string name)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
namestringThe fully qualified logger name to look for.
Returns
- ILogger
The logger found, or
nullif the named logger does not exist in the specified assembly's repository.
Remarks
If the named logger exists (in the specified assembly's repository) then it
returns a reference to the logger, otherwise it returns
null.
Exists(string, string)
Returns the named logger if it exists.
public static ILogger Exists(string repository, string name)
Parameters
repositorystringThe repository to lookup in.
namestringThe fully qualified logger name to look for.
Returns
- ILogger
The logger found, or
nullif the named logger does not exist in the specified repository.
Remarks
If the named logger exists (in the specified repository) then it
returns a reference to the logger, otherwise it returns
null.
GetAllRepositories()
Gets an array of all currently defined repositories.
public static ILoggerRepository[] GetAllRepositories()
Returns
- ILoggerRepository[]
An array of all the known ILoggerRepository objects.
Remarks
Gets an array of all currently defined repositories.
GetCurrentLoggers(Assembly)
Returns all the currently defined loggers in the specified assembly's repository.
public static ILogger[] GetCurrentLoggers(Assembly repositoryAssembly)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
Returns
- ILogger[]
All the defined loggers.
Remarks
The root logger is not included in the returned array.
GetCurrentLoggers(string)
Returns all the currently defined loggers in the specified repository.
public static ILogger[] GetCurrentLoggers(string repository)
Parameters
repositorystringThe repository to lookup in.
Returns
- ILogger[]
All the defined loggers.
Remarks
The root logger is not included in the returned array.
GetLogger(Assembly, string)
Retrieves or creates a named logger.
public static ILogger GetLogger(Assembly repositoryAssembly, string name)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
namestringThe name of the logger to retrieve.
Returns
- ILogger
The logger with the name specified.
Remarks
Retrieves a logger named as the name
parameter. If the named logger already exists, then the
existing instance will be returned. Otherwise, a new instance is
created.
By default, loggers do not have a set level but inherit it from the hierarchy. This is one of the central features of log4net.
GetLogger(Assembly, Type)
Shorthand for LogManager.GetLogger(string).
public static ILogger GetLogger(Assembly repositoryAssembly, Type type)
Parameters
repositoryAssemblyAssemblythe assembly to use to lookup the repository
typeTypeThe
typeof which the fullname will be used as the name of the logger to retrieve.
Returns
- ILogger
The logger with the name specified.
Remarks
Gets the logger for the fully qualified name of the type specified.
GetLogger(string, string)
Retrieves or creates a named logger.
public static ILogger GetLogger(string repository, string name)
Parameters
Returns
- ILogger
The logger with the name specified.
Remarks
Retrieves a logger named as the name
parameter. If the named logger already exists, then the
existing instance will be returned. Otherwise, a new instance is
created.
By default, loggers do not have a set level but inherit it from the hierarchy. This is one of the central features of log4net.
GetLogger(string, Type)
Shorthand for LogManager.GetLogger(string).
public static ILogger GetLogger(string repository, Type type)
Parameters
repositorystringThe repository to lookup in.
typeTypeThe
typeof which the fullname will be used as the name of the logger to retrieve.
Returns
- ILogger
The logger with the name specified.
Remarks
Gets the logger for the fully qualified name of the type specified.
GetLoggerRepository(Assembly)
Returns the default ILoggerRepository instance.
[Obsolete("Use GetRepository instead of GetLoggerRepository")]
public static ILoggerRepository GetLoggerRepository(Assembly repositoryAssembly)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
Returns
- ILoggerRepository
The default ILoggerRepository instance.
GetLoggerRepository(string)
Return the default ILoggerRepository instance.
[Obsolete("Use GetRepository instead of GetLoggerRepository")]
public static ILoggerRepository GetLoggerRepository(string repository)
Parameters
repositorystringthe repository to lookup in
Returns
- ILoggerRepository
Return the default ILoggerRepository instance
Remarks
Gets the ILoggerRepository for the repository specified
by the repository argument.
GetRepository(Assembly)
Returns the default ILoggerRepository instance.
public static ILoggerRepository GetRepository(Assembly repositoryAssembly)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
Returns
- ILoggerRepository
The default ILoggerRepository instance.
Remarks
Returns the default ILoggerRepository instance.
GetRepository(string)
Return the default ILoggerRepository instance.
public static ILoggerRepository GetRepository(string repository)
Parameters
repositorystringthe repository to lookup in
Returns
- ILoggerRepository
Return the default ILoggerRepository instance
Remarks
Gets the ILoggerRepository for the repository specified
by the repository argument.
ResetConfiguration(Assembly)
Resets all values contained in this repository instance to their defaults.
public static void ResetConfiguration(Assembly repositoryAssembly)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository to reset.
Remarks
Resets all values contained in the repository instance to their
defaults. This removes all appenders from all loggers, sets
the level of all non-root loggers to null,
sets their additivity flag to true and sets the level
of the root logger to Debug. Moreover,
message disabling is set its default "off" value.
ResetConfiguration(string)
Resets all values contained in this repository instance to their defaults.
public static void ResetConfiguration(string repository)
Parameters
repositorystringThe repository to reset.
Remarks
Resets all values contained in the repository instance to their
defaults. This removes all appenders from all loggers, sets
the level of all non-root loggers to null,
sets their additivity flag to true and sets the level
of the root logger to Debug. Moreover,
message disabling is set its default "off" value.
Shutdown()
Shuts down the log4net system.
public static void Shutdown()
Remarks
Calling this method will safely close and remove all appenders in all the loggers including root contained in all the default repositories.
Some appenders need to be closed before the application exists. Otherwise, pending logging events might be lost.
The shutdown method is careful to close nested
appenders before closing regular appenders. This is allows
configurations where a regular appender is attached to a logger
and again to a nested appender.
ShutdownRepository(Assembly)
Shuts down the repository for the repository specified.
public static void ShutdownRepository(Assembly repositoryAssembly)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
Remarks
Calling this method will safely close and remove all
appenders in all the loggers including root contained in the
repository for the repository. The repository is looked up using
the repositoryAssembly specified.
Some appenders need to be closed before the application exists. Otherwise, pending logging events might be lost.
The shutdown method is careful to close nested
appenders before closing regular appenders. This is allows
configurations where a regular appender is attached to a logger
and again to a nested appender.
ShutdownRepository(string)
Shuts down the repository for the repository specified.
public static void ShutdownRepository(string repository)
Parameters
repositorystringThe repository to shutdown.
Remarks
Calling this method will safely close and remove all
appenders in all the loggers including root contained in the
repository for the repository specified.
Some appenders need to be closed before the application exists. Otherwise, pending logging events might be lost.
The shutdown method is careful to close nested
appenders before closing regular appenders. This is allows
configurations where a regular appender is attached to a logger
and again to a nested appender.