Class Hierarchy
- Namespace
- log4net.Repository.Hierarchy
- Assembly
- log4net.dll
Hierarchical organization of loggers
public class Hierarchy : LoggerRepositorySkeleton, ILoggerRepository, IBasicRepositoryConfigurator, IXmlRepositoryConfigurator
- Inheritance
-
Hierarchy
- Implements
- Inherited Members
Remarks
The casual user should not have to deal with this class directly.
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy. Implements the ILoggerRepository interface.
The structure of the logger hierarchy is maintained by the GetLogger(string) method. The hierarchy is such that children link to their parent but parents do not have any references to their children. Moreover, loggers can be instantiated in any order, in particular descendant before ancestor.
In case a descendant is created before a particular ancestor, then it creates a provision node for the ancestor and adds itself to the provision node. Other descendants of the same ancestor add themselves to the previously created provision node.
Constructors
Hierarchy()
Default constructor
public Hierarchy()
Remarks
Initializes a new instance of the Hierarchy class.
Hierarchy(ILoggerFactory)
Construct with a logger factory
public Hierarchy(ILoggerFactory loggerFactory)
Parameters
loggerFactoryILoggerFactoryThe factory to use to create new logger instances.
Remarks
Initializes a new instance of the Hierarchy class with the specified ILoggerFactory.
Hierarchy(PropertiesDictionary)
Construct with properties
public Hierarchy(PropertiesDictionary properties)
Parameters
propertiesPropertiesDictionaryThe properties to pass to this repository.
Remarks
Initializes a new instance of the Hierarchy class.
Hierarchy(PropertiesDictionary, ILoggerFactory)
Construct with properties and a logger factory
public Hierarchy(PropertiesDictionary properties, ILoggerFactory loggerFactory)
Parameters
propertiesPropertiesDictionaryThe properties to pass to this repository.
loggerFactoryILoggerFactoryThe factory to use to create new logger instances.
Remarks
Initializes a new instance of the Hierarchy class with the specified ILoggerFactory.
Properties
EmittedNoAppenderWarning
Has no appender warning been emitted
public bool EmittedNoAppenderWarning { get; set; }
Property Value
Remarks
Flag to indicate if we have already issued a warning about not having an appender warning.
LoggerFactory
Gets or sets the default ILoggerFactory instance.
public ILoggerFactory LoggerFactory { get; set; }
Property Value
- ILoggerFactory
The default ILoggerFactory
Remarks
The logger factory is used to create logger instances.
Root
Get the root of this hierarchy
public Logger Root { get; }
Property Value
Remarks
Get the root of this hierarchy.
Methods
BasicRepositoryConfigure(params IAppender[])
Initialize the log4net system using the specified appenders
protected void BasicRepositoryConfigure(params IAppender[] appenders)
Parameters
appendersIAppender[]the appenders to use to log all logging events
Remarks
This method provides the same functionality as the IBasicRepositoryConfigurator.Configure(IAppender) method implemented on this object, but it is protected and therefore can be called by subclasses.
Clear()
Clear all logger definitions from the internal hashtable
public void Clear()
Remarks
This call will clear all logger definitions from the internal hashtable. Invoking this method will irrevocably mess up the logger hierarchy.
You should really know what you are doing before invoking this method.
Exists(string)
Test if a logger exists
public override ILogger Exists(string name)
Parameters
namestringThe name of the logger to lookup
Returns
- ILogger
The Logger object with the name specified
Remarks
Check if the named logger exists in the hierarchy. If so return
its reference, otherwise returns null.
GetAppenders()
Returns all the Appenders that are currently configured
public override IAppender[] GetAppenders()
Returns
- IAppender[]
An array containing all the currently configured appenders
Remarks
Returns all the IAppender instances that are currently configured. All the loggers are searched for appenders. The appenders may also be containers for appenders and these are also searched for additional loggers.
The list returned is unordered but does not contain duplicates.
GetCurrentLoggers()
Returns all the currently defined loggers in the hierarchy as an Array
public override ILogger[] GetCurrentLoggers()
Returns
- ILogger[]
All the defined loggers
Remarks
Returns all the currently defined loggers in the hierarchy as an Array. The root logger is not included in the returned enumeration.
GetLogger(string)
Return a new logger instance named as the first parameter using the default factory.
public override ILogger GetLogger(string name)
Parameters
namestringThe name of the logger to retrieve
Returns
- ILogger
The logger object with the name specified
Remarks
Return a new logger instance named as the first parameter using the default factory.
If a logger of that name already exists, then it will be returned. Otherwise, a new logger will be instantiated and then linked with its existing ancestors as well as children.
GetLogger(string, ILoggerFactory)
Return a new logger instance named as the first parameter using
factory.
public Logger GetLogger(string name, ILoggerFactory factory)
Parameters
namestringThe name of the logger to retrieve
factoryILoggerFactoryThe factory that will make the new logger instance
Returns
- Logger
The logger object with the name specified
Remarks
If a logger of that name already exists, then it will be
returned. Otherwise, a new logger will be instantiated by the
factory parameter and linked with its existing
ancestors as well as children.
IsDisabled(Level)
Test if this hierarchy is disabled for the specified Level.
public bool IsDisabled(Level level)
Parameters
levelLevelThe level to check against.
Returns
- bool
trueif the repository is disabled for the level argument,falseotherwise.
Remarks
If this hierarchy has not been configured then this method will
always return true.
This method will return true if this repository is
disabled for level object passed as parameter and
false otherwise.
See also the Threshold property.
Log(LoggingEvent)
Log the logEvent through this hierarchy.
public override void Log(LoggingEvent logEvent)
Parameters
logEventLoggingEventthe event to log
Remarks
This method should not normally be used to log. The ILog interface should be used for routine logging. This interface can be obtained using the log4net.LogManager.GetLogger(string) method.
The logEvent is delivered to the appropriate logger and
that logger is then responsible for logging the event.
OnLoggerCreationEvent(Logger)
Sends a logger creation event to all registered listeners
protected virtual void OnLoggerCreationEvent(Logger logger)
Parameters
loggerLoggerThe newly created logger
Remarks
Raises the logger creation event.
ResetConfiguration()
Reset all values contained in this hierarchy instance to their default.
public override void ResetConfiguration()
Remarks
Reset all values contained in this hierarchy instance to their
default. 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.
Existing loggers are not removed. They are just reset.
This method should be used sparingly and with care as it will block all logging until it is completed.
Shutdown()
Shutting down a hierarchy will safely close and remove all appenders in all loggers including the root logger.
public override void Shutdown()
Remarks
Shutting down a hierarchy will safely close and remove all appenders in all loggers including the root logger.
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.
XmlRepositoryConfigure(XmlElement)
Initialize the log4net system using the specified config
protected void XmlRepositoryConfigure(XmlElement element)
Parameters
elementXmlElementthe element containing the root of the config
Remarks
This method provides the same functionality as the IBasicRepositoryConfigurator.Configure(IAppender) method implemented on this object, but it is protected and therefore can be called by subclasses.
Events
LoggerCreatedEvent
Event used to notify that a logger has been created.
public event LoggerCreationEventHandler LoggerCreatedEvent
Event Type
Remarks
Event raised when a logger is created.