Table of Contents

Class DiagnosticLogger

Namespace
SwiftCollections.Diagnostics
Assembly
SwiftCollections.dll

Provides reusable logger state and diagnostic channels for libraries built on SwiftCollections diagnostics.

public abstract class DiagnosticLogger
Inheritance
DiagnosticLogger
Inherited Members

Remarks

Static logger facades can delegate to a derived instance of this type while keeping their existing public API.

Constructors

DiagnosticLogger(string)

Initializes a new instance of the DiagnosticLogger class.

protected DiagnosticLogger(string channelName)

Parameters

channelName string

The diagnostic channel name.

Properties

Channel

Gets the diagnostic channel used for normal diagnostics.

public DiagnosticChannel Channel { get; }

Property Value

DiagnosticChannel

CustomFormatter

Gets or sets the formatter used to transform log arguments into a final log entry. Assigning null restores DefaultLogFormatter(DiagnosticLevel, string, string).

public Func<DiagnosticLevel, string, string, string> CustomFormatter { get; set; }

Property Value

Func<DiagnosticLevel, string, string, string>

DebugChannel

Gets the diagnostic channel used for verbose debug diagnostics.

public DiagnosticChannel DebugChannel { get; }

Property Value

DiagnosticChannel

EnableDebugLogging

Gets or sets a value indicating whether verbose debug diagnostics should be emitted.

public bool EnableDebugLogging { get; set; }

Property Value

bool

LogHandler

Gets or sets the delegate used to write formatted log messages. Assigning null restores DefaultLogHandler(DiagnosticLevel, string, string).

public Action<DiagnosticLevel, string, string> LogHandler { get; set; }

Property Value

Action<DiagnosticLevel, string, string>

MinimumLevel

Gets or sets the minimum severity required for normal diagnostics to be emitted.

public DiagnosticLevel MinimumLevel { get; set; }

Property Value

DiagnosticLevel

Name

Gets the logger name.

public string Name { get; }

Property Value

string

Methods

DefaultLogFormatter(DiagnosticLevel, string, string)

Formats a log entry using a deterministic, source-first layout.

public virtual string DefaultLogFormatter(DiagnosticLevel level, string message, string source)

Parameters

level DiagnosticLevel

The severity level of the log message.

message string

The log message.

source string

The source of the log message.

Returns

string

A formatted log entry.

DefaultLogHandler(DiagnosticLevel, string, string)

Writes a log message using the current CustomFormatter.

public virtual void DefaultLogHandler(DiagnosticLevel level, string message, string source)

Parameters

level DiagnosticLevel

The severity level of the log message.

message string

The log message.

source string

The source of the log message.

HandleDiagnosticEvent(in DiagnosticEvent)

Receives diagnostics emitted by either channel.

protected virtual void HandleDiagnosticEvent(in DiagnosticEvent diagnostic)

Parameters

diagnostic DiagnosticEvent

The emitted diagnostic event.

IsEnabled(DiagnosticLevel)

Determines whether normal diagnostics at the specified level are currently enabled.

public bool IsEnabled(DiagnosticLevel level)

Parameters

level DiagnosticLevel

The diagnostic level to evaluate.

Returns

bool

true when messages at level will be emitted; otherwise, false.

ResolveSource(in DiagnosticEvent)

Resolves the source value passed to LogHandler.

protected virtual string ResolveSource(in DiagnosticEvent diagnostic)

Parameters

diagnostic DiagnosticEvent

The emitted diagnostic event.

Returns

string

The resolved source.