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
-
objectHostLogger
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
loggerILoggerThe logger that receives entries, enabled checks, and scopes.
factoryILoggerFactoryThe 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
stateTStateThe 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
TStateThe 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
logLevelLogLevelThe 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
environmentIHostEnvironmentAn optional host environment whose environment name is included in the message.
Type Parameters
TA 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
logLevelLogLevelThe severity of the entry.
eventIdEventIdThe identifier of the event.
stateTStateThe entry's state.
exceptionExceptionAn optional exception associated with the entry.
formatterFunc<TState, Exception, string>The function that formats the state and exception as a message.
Type Parameters
TStateThe type of the log entry state.