Class TextLogger
Provides a logger that makes a line's text once, for the logger behind it: the time in UTC, the category, the level and the scopes, the event's name, the message and the exception; it hands that over as the message.
public sealed class TextLogger : ILogger
- Inheritance
-
TextLogger
- Implements
- Inherited Members
Remarks
A line reads HH:mm:ss.ffff | category | Info | scope => scope | event | message: the time in UTC, the level's first
four characters, the scopes separated by =>, the event's name without its number, and after the message
Exception: and the exception's text. A single line has every line break written as \n; otherwise the
entry ends with a line break.
Constructors
TextLogger(ILogger, bool, bool, bool, string?, bool)
Provides a logger that makes a line's text once, for the logger behind it: the time in UTC, the category, the level and the scopes, the event's name, the message and the exception; it hands that over as the message.
public TextLogger(ILogger logger, bool singleLine = true, bool includeTime = true, bool includeScopes = true, string? categoryName = null, bool includeLevel = true)
Parameters
loggerILoggerThe logger behind it.
singleLinebooltrue for one line per entry, its own line breaks written as
\n, for a destination that keeps each line as an entry of its own.includeTimebooltrue to write the time; false where the destination stamps its lines itself.
includeScopesbooltrue to write the scopes.
categoryNamestringThe category to write, or null for none.
includeLevelbooltrue to write the level; false where the destination records it itself.
Remarks
A line reads HH:mm:ss.ffff | category | Info | scope => scope | event | message: the time in UTC, the level's first
four characters, the scopes separated by =>, the event's name without its number, and after the message
Exception: and the exception's text. A single line has every line break written as \n; otherwise the
entry ends with a line break.
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.
Remarks
The scopes are its own, written into each line with includeScopes.
IsEnabled(LogLevel)
Checks if the given logLevel is enabled.
public bool IsEnabled(LogLevel logLevel)
Parameters
logLevelLogLevelLevel to be checked.
Returns
Remarks
It asks the logger behind it.
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.
Remarks
It writes the line's text to the logger behind it, when that one takes the level.