Table of Contents

Class HostLogger

Namespace
Invex.Extensions.Logging.Utils
Assembly
Invex.Extensions.Logging.Utils.dll

Delegates logging to an Microsoft.Extensions.Logging.ILogger and owns the lifetime of an associated logger factory.

public sealed class HostLogger
Inheritance
object
HostLogger

Remarks

CreateHostLogger(Action<ILoggingBuilder>?) creates this wrapper with the category Host. When constructing it directly, supply a factory whose ownership can be transferred to this wrapper; disposing it can also affect other loggers created by that factory. The wrapper does not add filtering or catch logging failures.

Constructors

HostLogger(ILogger, ILoggerFactory)

Delegates logging to an Microsoft.Extensions.Logging.ILogger and owns the lifetime of an associated logger factory.

public HostLogger(ILogger logger, ILoggerFactory factory)

Parameters

logger ILogger

The logger that receives entries, enabled checks, and scopes.

factory ILoggerFactory

The factory disposed when this wrapper is disposed.

Remarks

CreateHostLogger(Action<ILoggingBuilder>?) creates this wrapper with the category Host. When constructing it directly, supply a factory whose ownership can be transferred to this wrapper; disposing it can also affect other loggers created by that factory. The wrapper does not add filtering or catch logging failures.

Methods

BeginScope<TState>(TState)

Begins a scope on the wrapped logger.

public IDisposable? BeginScope<TState>(TState state) where TState : notnull

Parameters

state TState

The scope state forwarded to the logger.

Returns

IDisposable

A scope that should be disposed when complete, or null if the logger returns no scope.

Type Parameters

TState

The type of the non-null scope state.

Dispose()

Disposes the associated factory and its owned logging providers.

public void Dispose()

Remarks

This method delegates directly to the factory. Dispose after completing logging; providers such as the buffered file logger use disposal to drain queued entries.

IsEnabled(LogLevel)

Checks whether the wrapped logger enables the specified level.

public bool IsEnabled(LogLevel logLevel)

Parameters

logLevel LogLevel

The level to check.

Returns

bool

The wrapped logger's enabled state for the specified level.

LogStartupInfo<T>(IHostEnvironment?)

Writes startup information using the assembly containing T and the current machine.

public void LogStartupInfo<T>(IHostEnvironment? environment = null)

Parameters

environment IHostEnvironment

An optional host environment whose environment name is included in the message.

Type Parameters

T

A type whose assembly supplies the application name and assembly version.

Remarks

Delegates to LogStartupInfo<T>(ILogger, IHostEnvironment?). The message is written at Microsoft.Extensions.Logging.LogLevel.Information only when enabled, and does not verify host startup.

Log<TState>(LogLevel, EventId, TState, Exception?, Func<TState, Exception?, string>)

Forwards an entry to the wrapped logger.

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)

Parameters

logLevel LogLevel

The severity of the entry.

eventId EventId

The identifier of the event.

state TState

The entry's state.

exception Exception

An optional exception associated with the entry.

formatter Func<TState, Exception, string>

The function that formats the state and exception as a message.

Type Parameters

TState

The type of the log entry state.