Class LoggerRoot
- Namespace
- Switchboard
- Assembly
- Switchboard.Logger.dll
Represents a logger composed of other ILogger implementations, which serve as the actual targets for log output. A LoggerRoot cannot have another LoggerRoot added as a log target. Adding and removing targets are thread safe operations, but changes may not be immediate across threads. Thread safety of logging operations are left up to the target implementations of the ILogger interface.
public sealed class LoggerRoot : ILogger
- Inheritance
-
LoggerRoot
- Implements
- Extension Methods
Properties
LogLevel
Gets or sets the overall LogLevel for all log targets within the LoggerRoot. If the LogLevel of a message or exception is less significant, it will not be sent to any log targets. The value may not be immediately accurate across all threads.
public LogLevel LogLevel { get; set; }
Methods
Add(ILogger)
Adds an implementation of ILogger to the LoggerRoot as a log target.
public bool Add(ILogger logTarget)
Parameters
logTargetILoggerThe logger to add.
Returns
- bool
Returns false if the
logTargethas already been added to the LoggerRoot, otherwise returns true.
Exceptions
- ArgumentNullException
Thrown if the
logTargetis null.- ArgumentException
Thrown if the
logTargetis a LoggerRoot.
Contains(ILogger)
Determines whether a log target has been added.
public bool Contains(ILogger logTarget)
Parameters
logTargetILoggerThe logger to search for.
Returns
- bool
Returns true if the
logTargetis contained within, otherwise false.
Exceptions
- ArgumentNullException
Thrown if the
logTargetis null.
Log(LogLevel, Exception, ReadOnlySpan<char>)
Writes an exception to the log. Log targets should never attempt to throw an exception when logging an exception. If a log target throws an exception during the method, it is silently consumed.
public void Log(LogLevel logLevel, Exception exception, ReadOnlySpan<char> message)
Parameters
logLevelLogLevelThe level of significance assigned to the exception.
exceptionExceptionThe exception to log.
messageReadOnlySpan<char>A log message to be included with the exception.
Exceptions
- ArgumentNullException
Thrown if the
exceptionis null.
Log(LogLevel, ReadOnlySpan<char>, string, string, int)
Writes a message to the log. If a log target throws an exception, it will be captured until all log targets have had a chance to log, then re-thrown. If multiple exceptions are thrown, they will all be re-thrown as one AggregateException.
public void Log(LogLevel logLevel, ReadOnlySpan<char> message, string memberName = null, string filePath = null, int lineNumber = 0)
Parameters
logLevelLogLevelThe level of significance assigned to the message.
messageReadOnlySpan<char>The log message.
memberNamestringThe name of the member that called the method. Do not provide an argument. The compiler will automatically assign the correct value.
filePathstringThe name of the file that contains the member that called the method. Do not provide an argument. The compiler will automatically assign the correct value.
lineNumberintThe line number within the file that contains the member that called the method. Do not provide an argument. The compiler will automatically assign the correct value.
Remove(ILogger)
Removes a log target.
public bool Remove(ILogger logTarget)
Parameters
logTargetILoggerThe logger to remove.
Returns
- bool
Returns true if the
logTargetwas found and removed, otherwise false.
Exceptions
- ArgumentNullException
Thrown if the
logTargetis null.
RemoveAllTargets()
Removes all loggers from the log target list.
public void RemoveAllTargets()