Class LogWriter
Provides a collection of log writer implementations for writing log messages to various outputs.
public static class LogWriter
- Inheritance
-
LogWriter
Remarks
The LogWriter class contains nested implementations of the ILogWriter interface, including LogWriter.NullLogWriter, LogWriter.DebugLogWriter, LogWriter.ConsoleLogWriter and others. These implementations allow for logging to different targets, such as the debug output or the console. Additionally, the class defines common logging behavior that can be shared across different log writer implementations.
Fields
- Null
Represents a no-op implementation of the ILogWriter interface.
- SeparatorChar
Represents the default character used to separate values in formatted output. This is used in WriteSeparator(ILogWriter).
- SeparatorLength
Specifies the default length, in characters, for a separator line. This is used in WriteSeparator(ILogWriter).
Properties
- Application
Gets or sets the log writer instance used for application-level logging.
- Console
Gets or sets the log writer for console output.
- Current
Gets or sets the current instance of the ILogWriter used for logging.
- Debug
Gets or sets the log writer used for debug-level logging.
- IndentLength
Represents the default number of spaces used for indentation.
- Multi
Gets or sets the shared instance of LogWriter.MultiLogWriter used for logging operations.
Methods
- BeginSection(ILogWriter, string?)
Begins a new indented log section, optionally with a title, and returns the log writer for further logging within the section.
- Create(params ILogWriter[])
Creates a new instance of a log writer that writes log messages to multiple loggers.
- Create(Action<string>)
Creates an instance of an ILogWriter that writes log messages using the specified action.
- Create(TextWriter)
Creates a new instance of an ILogWriter that writes log messages to the specified TextWriter.
- Create(StringBuilder)
Creates a new instance of an ILogWriter that writes log messages to the specified StringBuilder.
- EndSection(ILogWriter)
Ends the current log section by decreasing the indentation level and writing a section separator.
- Safe(ILogWriter?)
Ensures that a non-null ILogWriter instance is returned.
- Write(ILogWriter, StringBuilder)
Writes the content of the specified StringBuilder to the output, line by line. This is a convenience method that splits the content into lines and writes each line.
- WriteException(ILogWriter, Exception)
Writes detailed information about the specified exception to the log, including its type, message, and stack trace.
- WriteException(ILogWriter, string, Exception)
Writes detailed information about an exception, including its type, message, and stack trace, to the log writer as a formatted section.
- WriteKeyValue(ILogWriter, object, object?)
Writes a key-value pair to the log in the format "key: value".
- WriteLine(ILogWriter)
Writes an empty line to the log output using the specified log writer.
- WriteLines(ILogWriter, IEnumerable<string>)
Writes each string in the specified collection to the log, appending a new line after each entry.
- WriteLines(ILogWriter, IEnumerable)
Writes each item in the specified collection to the log as a separate line.
- WriteLines(ILogWriter, params object?[])
Writes each specified line to the log using the provided writer.
- WriteLines(ILogWriter, params string[])
Writes each string in the specified collection to the log as a separate line.
- WriteSeparator(ILogWriter)
Writes a separator line to the log using the specified log writer.