Table of Contents

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

logTarget ILogger

The logger to add.

Returns

bool

Returns false if the logTarget has already been added to the LoggerRoot, otherwise returns true.

Exceptions

ArgumentNullException

Thrown if the logTarget is null.

ArgumentException

Thrown if the logTarget is a LoggerRoot.

Contains(ILogger)

Determines whether a log target has been added.

public bool Contains(ILogger logTarget)

Parameters

logTarget ILogger

The logger to search for.

Returns

bool

Returns true if the logTarget is contained within, otherwise false.

Exceptions

ArgumentNullException

Thrown if the logTarget is 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

logLevel LogLevel

The level of significance assigned to the exception.

exception Exception

The exception to log.

message ReadOnlySpan<char>

A log message to be included with the exception.

Exceptions

ArgumentNullException

Thrown if the exception is 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

logLevel LogLevel

The level of significance assigned to the message.

message ReadOnlySpan<char>

The log message.

memberName string

The name of the member that called the method. Do not provide an argument. The compiler will automatically assign the correct value.

filePath string

The 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.

lineNumber int

The 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

logTarget ILogger

The logger to remove.

Returns

bool

Returns true if the logTarget was found and removed, otherwise false.

Exceptions

ArgumentNullException

Thrown if the logTarget is null.

RemoveAllTargets()

Removes all loggers from the log target list.

public void RemoveAllTargets()