Class LogManager
- Namespace
- log4net
- Assembly
- log4net.dll
This class is used by client applications to request logger instances.
public sealed class LogManager
- Inheritance
-
LogManager
- Inherited Members
Examples
Simple example of logging messages
<pre><code class="lang-csharp">ILog log = LogManager.GetLogger("application-log");
log.Info("Application Start"); log.Debug("This is a debug message");
if (log.IsDebugEnabled) { log.Debug("This is another debug message"); }
Remarks
This class has static methods that are used by a client to request a logger instance. The GetLogger(string) method is used to retrieve a logger.
See the ILog interface for more details.
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.
CreateDomain(Type)
Creates a repository with the specified repository type.
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(Type repositoryType)
Parameters
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() will return the same repository instance.
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.
CreateRepository(Type)
Creates a repository with the specified repository type.
public static ILoggerRepository CreateRepository(Type repositoryType)
Parameters
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() will return the same repository instance.
Exists(Assembly, string)
Returns the named logger if it exists.
public static ILog Exists(Assembly repositoryAssembly, string name)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
namestringThe fully qualified logger name to look for.
Returns
- ILog
The logger, or
nullif the logger doesn't exist in the specified assembly's repository.
Remarks
If the named logger exists (in the repository for the specified assembly) then it
returns a reference to the logger, otherwise it returns
null.
Exists(string)
Returns the named logger if it exists.
public static ILog Exists(string name)
Parameters
namestringThe fully qualified logger name to look for.
Returns
- ILog
The logger found, or
nullif no logger could be found.
Remarks
If the named logger exists (in the default 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 ILog Exists(string repository, string name)
Parameters
repositorystringThe repository to lookup in.
namestringThe fully qualified logger name to look for.
Returns
- ILog
The logger found, or
nullif the logger doesn't 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 the list of currently defined repositories.
public static ILoggerRepository[] GetAllRepositories()
Returns
- ILoggerRepository[]
An array of all the known ILoggerRepository objects.
Remarks
Get an array of all the ILoggerRepository objects that have been created.
GetCurrentLoggers()
Returns all the currently defined loggers in the default repository.
public static ILog[] GetCurrentLoggers()
Returns
- ILog[]
All the defined loggers.
Remarks
The root logger is not included in the returned array.
GetCurrentLoggers(Assembly)
Returns all the currently defined loggers in the specified assembly's repository.
public static ILog[] GetCurrentLoggers(Assembly repositoryAssembly)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
Returns
- ILog[]
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 ILog[] GetCurrentLoggers(string repository)
Parameters
repositorystringThe repository to lookup in.
Returns
- ILog[]
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 ILog GetLogger(Assembly repositoryAssembly, string name)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
namestringThe name of the logger to retrieve.
Returns
- ILog
The logger with the name specified.
Remarks
Retrieve 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 ILog GetLogger(Assembly repositoryAssembly, Type type)
Parameters
repositoryAssemblyAssemblyThe assembly to use to lookup the repository.
typeTypeThe full name of
typewill be used as the name of the logger to retrieve.
Returns
- ILog
The logger with the name specified.
Remarks
Gets the logger for the fully qualified name of the type specified.
GetLogger(string)
Retrieves or creates a named logger.
public static ILog GetLogger(string name)
Parameters
namestringThe name of the logger to retrieve.
Returns
- ILog
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, string)
Retrieves or creates a named logger.
public static ILog GetLogger(string repository, string name)
Parameters
Returns
- ILog
The logger with the name specified.
Remarks
Retrieve 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 ILog GetLogger(string repository, Type type)
Parameters
repositorystringThe repository to lookup in.
typeTypeThe full name of
typewill be used as the name of the logger to retrieve.
Returns
- ILog
The logger with the name specified.
Remarks
Gets the logger for the fully qualified name of the type specified.
GetLogger(Type)
Shorthand for LogManager.GetLogger(string).
public static ILog GetLogger(Type type)
Parameters
typeTypeThe full name of
typewill be used as the name of the logger to retrieve.
Returns
- ILog
The logger with the name specified.
Remarks
Get the logger for the fully qualified name of the type specified.
GetLoggerRepository()
Returns the default ILoggerRepository instance.
[Obsolete("Use GetRepository instead of GetLoggerRepository")]
public static ILoggerRepository GetLoggerRepository()
Returns
- ILoggerRepository
The ILoggerRepository instance for the default repository.
Remarks
Gets the ILoggerRepository for the repository specified by the callers assembly (Assembly.GetCallingAssembly()).
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.
Remarks
Gets the ILoggerRepository for the repository specified
by the repositoryAssembly argument.
GetLoggerRepository(string)
Returns the default ILoggerRepository instance.
[Obsolete("Use GetRepository instead of GetLoggerRepository")]
public static ILoggerRepository GetLoggerRepository(string repository)
Parameters
repositorystringThe repository to lookup in.
Returns
- ILoggerRepository
The default ILoggerRepository instance.
Remarks
Gets the ILoggerRepository for the repository specified
by the repository argument.
GetRepository()
Returns the default ILoggerRepository instance.
public static ILoggerRepository GetRepository()
Returns
- ILoggerRepository
The ILoggerRepository instance for the default repository.
Remarks
Gets the ILoggerRepository for the repository specified by the callers assembly (Assembly.GetCallingAssembly()).
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
Gets the ILoggerRepository for the repository specified
by the repositoryAssembly argument.
GetRepository(string)
Returns the default ILoggerRepository instance.
public static ILoggerRepository GetRepository(string repository)
Parameters
repositorystringThe repository to lookup in.
Returns
- ILoggerRepository
The default ILoggerRepository instance.
Remarks
Gets the ILoggerRepository for the repository specified
by the repository argument.
ResetConfiguration()
Resets all values contained in this repository instance to their defaults.
public static void ResetConfiguration()
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 to its default "off" value.
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
Reset 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 to 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
Reset 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 to 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()
Shuts down the default repository.
public static void ShutdownRepository()
Remarks
Calling this method will safely close and remove all appenders in all the loggers including root contained in the default repository.
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 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. 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 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.