Class NullLoggerWrapper<T>
- Namespace
- Arc4u.Diagnostics
- Assembly
- Arc4u.Diagnostics.dll
Helper class to unit test the Arc4u logging.
public class NullLoggerWrapper<T> : ILoggerWrapper<T>, ILogger<T>, ILogger, ILoggerCallerMember
Type Parameters
TThe category type of the logger.
- Inheritance
-
NullLoggerWrapper<T>
- Implements
-
ILogger<T>
- Inherited Members
- Extension Methods
Fields
Instance
Gets the shared instance.
public static readonly NullLoggerWrapper<T> Instance
Field Value
Properties
AdditionalFields
Gets the additional properties that are written with the next log entry of this logger.
public Dictionary<string, object?> AdditionalFields { get; }
Property Value
Remarks
The properties are cleared once the entry is written.
IncludeStackTrace
Sets a value indicating whether the stack trace is added to the next log entry; reset once the entry is written.
public bool IncludeStackTrace { get; set; }
Property Value
Methods
BeginScope<TState>(TState)
Begins a logical operation scope.
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
Parameters
stateTStateThe identifier for the scope.
Returns
- IDisposable
An IDisposable that ends the logical operation scope on dispose.
Type Parameters
TStateThe type of the state to begin scope for.
CallerMemberName(string)
Sets the name of the calling member that is written in the MethodName property of the next log entries.
public void CallerMemberName(string caller)
Parameters
callerstringThe name of the calling method or property.
IsEnabled(LogLevel)
Checks if the given logLevel is enabled.
public bool IsEnabled(LogLevel logLevel)
Parameters
logLevelLogLevelLevel to be checked.
Returns
Log<TState>(LogLevel, EventId, TState, Exception?, Func<TState, Exception?, string>)
Writes a log entry.
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
Parameters
logLevelLogLevelEntry will be written on this level.
eventIdEventIdId of the event.
stateTStateThe entry to be written. Can be also an object.
exceptionExceptionThe exception related to this entry.
formatterFunc<TState, Exception, string>Function to create a string message of the
stateandexception.
Type Parameters
TStateThe type of the object to be written.
SetContext(string, string, Type?)
Returns a logger that writes its entries with the category, the calling member and optionally the source context type given.
public ILoggerWrapper<T> SetContext(string category, string caller = "", Type? realType = null)
Parameters
categorystringThe message category, see MessageCategory.
callerstringThe name of the calling member.
realTypeTypeThe type to report as the source context instead of
T, or null to keepT.
Returns
- ILoggerWrapper<T>
The logger wrapper to use for the entry.
Remarks
The returned logger has its own additional fields, so a logger shared between callers (or threads) is never modified by an entry being prepared.