Class FakeLogger
Represents a fake implementation of the ILogger interface, typically used as a test double to simulate logging behavior.
public class FakeLogger : ILogger
- Inheritance
-
FakeLogger
- Implements
-
ILogger
- Inherited Members
- Extension Methods
Properties
Messages
public List<string> Messages { get; }
Property Value
Methods
ForContext(IEnumerable<ILogEventEnricher>)
Creates a logger context enriched with the specified Serilog.Core.ILogEventEnricher instances. In this implementation, the enrichers are not applied and the current Serilog.ILogger instance is returned unchanged.
public ILogger ForContext(IEnumerable<ILogEventEnricher> enrichers)
Parameters
enrichersIEnumerable<ILogEventEnricher>The collection of enrichers intended to add contextual properties to log events.
Returns
- ILogger
The current Serilog.ILogger instance, without the supplied enrichers applied.
ForContext(string, object?, bool)
Creates a logger context enriched with the specified property and value, returning the same logger instance.
public ILogger ForContext(string propertyName, object? value, bool destructureObjects = false)
Parameters
propertyNamestringThe name of the property to add to the logger context.
valueobjectThe value associated with the property. Can be null.
destructureObjectsboolIndicates whether complex objects should be destructured. Defaults to false.
Returns
- ILogger
The current Serilog.ILogger instance.
ForContext(Type)
Returns the current logger instance, ignoring the provided source type. Provides a no-op context enrichment for log messages.
public ILogger ForContext(Type source)
Parameters
sourceTypeThe source type used to enrich the logger context.
Returns
- ILogger
The current Serilog.ILogger instance.
ForContext<TSource>()
Creates a logger context associated with the specified source type by returning the current Serilog.ILogger instance.
public ILogger ForContext<TSource>()
Returns
- ILogger
The current Serilog.ILogger instance.
Type Parameters
TSourceThe source type used to enrich the logger context.
IsEnabled(LogEventLevel)
Determines whether logging is enabled for the specified log event level. Currently returns true unconditionally, allowing all log levels to be processed.
public bool IsEnabled(LogEventLevel level)
Parameters
levelLogEventLevelThe log event level to evaluate.
Returns
- bool
trueif logging is enabled for the given level; otherwise,false.
Write(LogEvent)
Appends the rendered message of the provided log event to the internal messages collection.
public void Write(LogEvent logEvent)
Parameters
logEventLogEventThe log event whose rendered message will be added to the collection.
Write(LogEventLevel, Exception?, string, params object?[]?)
Captures a log entry by appending the formatted message to the internal Messages collection.
When propertyValues is provided, the messageTemplate is formatted with those values; otherwise the template is stored as-is.
If exception is not null, its message is appended as an additional entry.
public void Write(LogEventLevel level, Exception? exception, string messageTemplate, params object?[]? propertyValues)
Parameters
levelLogEventLevelThe severity level of the log event.
exceptionExceptionAn optional exception whose message is recorded when not null.
messageTemplatestringThe message template to log, used directly when
propertyValuesis null.propertyValuesobject[]Optional values to substitute into
messageTemplateviastring.Format.
Write(LogEventLevel, string, params object?[]?)
Writes a log message at the specified level to the internal messages collection, formatting it with the provided property values.
public void Write(LogEventLevel level, string messageTemplate, params object?[]? propertyValues)
Parameters
levelLogEventLevelThe severity level of the log event.
messageTemplatestringThe message template containing placeholders for the property values.
propertyValuesobject[]An optional array of objects to format the message template. Can be null.
Write<T>(LogEventLevel, Exception?, string, T)
Writes a log entry by formatting the provided message template with the supplied property value and appending it to the Messages collection. If an exception is supplied, its message is also appended to the collection.
public void Write<T>(LogEventLevel level, Exception? exception, string messageTemplate, T propertyValue)
Parameters
levelLogEventLevelThe severity level of the log event.
exceptionExceptionAn optional exception whose message, when not null, is added to the Messages collection after the formatted message.
messageTemplatestringThe message template string used to format the log entry.
propertyValueTThe value to be substituted into the message template.
Type Parameters
T
Write<T>(LogEventLevel, string, T)
Writes a log entry by formatting the provided message template with the given property value and adding it to the messages collection.
public void Write<T>(LogEventLevel level, string messageTemplate, T propertyValue)
Parameters
levelLogEventLevelThe log event level associated with the entry being written.
messageTemplatestringThe message template containing a format placeholder for the property value.
propertyValueTThe value to be inserted into the message template.
Type Parameters
TThe type of the property value to be substituted into the message template.