Class
LogStream
Provides a managed, asynchronous log writer which supports writing safe data to log files or text streams.
public class LogStream : IDisposable, IAsyncDisposableInheritance #
Derived #
Implements #
Inherited Members #
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Constructors #
| Name | Description |
|---|---|
| LogStream() | Creates an new LogStream instance with no predefined outputs. |
| LogStream(TextWriter) | Creates an new LogStream instance with the given TextWriter object. |
| LogStream(string) | Creates an new LogStream instance with the given relative or absolute file path. |
| LogStream(string?, TextWriter?) | Creates an new LogStream instance which writes text to an file and an TextWriter. |
Properties #
| Name | Description |
|---|---|
| ConsoleOutput | Gets a shared LogStream that writes its output to the Out stream. |
| Disposed | Gets an boolean indicating if this LogStream was disposed. |
| Empty | Gets a shared LogStream without any output stream. |
| Encoding | Gets or sets the encoding used for writting data to the output file. This property is only appliable if this instance is using an file-based output. |
| FilePath | Gets or sets the absolute path to the file where the log is being written to. |
| IsBuffering | Gets an boolean indicating if this LogStream is buffering output messages to their internal message buffer. |
| NormalizeEntries | Gets or sets a boolean that indicates that every input must be trimmed and have their line endings normalized before being written to the output stream. |
| RotatingPolicy | Gets the defined RotatingLogPolicy for this LogStream. |
| SafeTimestamp | Gets the current local date and time as a file-name-safe string formatted as “yyyy-MM-dd_HH-mm-ss”. |
| TextWriter | Gets the TextWriter object where the log is being written to. |
Methods #
| Name | Description |
|---|---|
| Close() | Writes all pending logs from the queue and closes all resources used by this object. |
| ConfigureRotatingPolicy(long, TimeSpan) | Defines the time interval and size threshold for starting the task, and then starts the task. This method is an shortcut for calling Configure of this defined RotatingPolicy method. |
| ConfigureRotatingPolicy(long, TimeSpan, RotatingLogPolicyCompressor) | Defines the time interval, size threshold, and compression strategy for starting the task, and then starts the task. |
| Dispose() | Writes all pending logs from the queue and closes all resources used by this object. |
| DisposeAsync() | Asynchronously writes all pending logs from the queue and closes all resources used by this object. |
| EscapeSafeDateTime(DateTime, IFormatProvider?) | Converts the specified DateTime to a file-name-safe string representation formatted as “yyyy-MM-dd_HH-mm-ss”. |
| ~LogStream() | |
| Flush() | Blocks the current thread until all currently enqueued content is written to the underlying streams. |
| FlushAsync() | Asynchronously waits until all currently enqueued content is written to the underlying streams. |
| Peek() | Reads the output buffer. To use this method, it’s required to set this LogStream buffering with StartBuffering. |
| PeekEntries() | Retrieves all buffered log entries as an array of strings. |
| SafeAppendToFile(string, string?) | Safely appends the specified string to the specified file path. |
| SafeAppendToFile(string, string?, Encoding) | Safely appends the specified string to the specified file path. |
| SafeAppendToFile(string, string[]) | Safely appends the specified lines to the specified file path. |
| SafeAppendToFile(string, string[], Encoding) | Safely appends the specified lines to the specified file path. |
| SafeAppendToFileAsync(string, string?, CancellationToken) | Safely appends the specified string to the specified file path asynchronously. |
| SafeAppendToFileAsync(string, string?, Encoding, CancellationToken) | Safely appends the specified string to the specified file path asynchronously. |
| SafeAppendToFileAsync(string, string[], CancellationToken) | Safely appends the specified lines to the specified file path asynchronously. |
| SafeAppendToFileAsync(string, string[], Encoding, CancellationToken) | Safely appends the specified lines to the specified file path asynchronously. |
| SafeWriteToFile(string, string?) | Safely writes the specified string to the specified file path. |
| SafeWriteToFile(string, string?, Encoding) | Safely writes the specified string to the specified file path. |
| SafeWriteToFile(string, string[]) | Safely writes the specified lines to the specified file path. |
| SafeWriteToFile(string, string[], Encoding) | Safely writes the specified lines to the specified file path. |
| SafeWriteToFileAsync(string, string?, CancellationToken) | Safely writes the specified string to the specified file path asynchronously. |
| SafeWriteToFileAsync(string, string?, Encoding, CancellationToken) | Safely writes the specified string to the specified file path asynchronously. |
| SafeWriteToFileAsync(string, string[], CancellationToken) | Safely writes the specified lines to the specified file path asynchronously. |
| SafeWriteToFileAsync(string, string[], Encoding, CancellationToken) | Safely writes the specified lines to the specified file path asynchronously. |
| StartBuffering(int) | Start buffering all output to an alternate stream in memory for readability with Peek later. |
| StopBuffering() | Stops buffering output. |
| Write(string) | Writes a message to the log stream. |
| Write(Exception) | Writes an exception to the log stream. |
| Write(LogStreamEntry) | Writes a log entry to the log stream. |
| WriteAsync(string) | Asynchronously writes a message to the log stream. |
| WriteAsync(Exception) | Asynchronously writes an exception to the log stream. |
| WriteAsync(LogStreamEntry) | Asynchronously writes a log entry to the log stream. |
| WriteException(Exception) | Writes an exception description in the log. |
| WriteException(Exception, string?) | Writes an exception description in the log. |
| WriteExceptionAsync(Exception) | Writes an exception description in the log. |
| WriteExceptionAsync(Exception, string?) | Writes an exception description in the log. |
| WriteLine() | Writes an line-break at the end of the output. |
| WriteLine(object?) | Writes the text and concats an line-break at the end into the output. |
| WriteLine(string) | Writes the text and concats an line-break at the end into the output. |
| WriteLine(string, params ReadOnlySpan<object?>) | Writes the text format and arguments and concats an line-break at the end into the output. |
| WriteLine(string, params IEnumerable<object?>) | Writes the text format and arguments and concats an line-break at the end into the output. |
| WriteLine(IFormatProvider?, string, params object?[]) | Writes the text format and arguments and appends a line-break at the end into the output, using the specified format provider. |
| WriteLineAsync() | Writes an line-break at the end of the output. |
| WriteLineAsync(object?) | Writes the text and concats an line-break at the end into the output. |
| WriteLineAsync(string) | Writes the text and concats an line-break at the end into the output. |
| WriteLineAsync(string, params IEnumerable<object?>) | Writes the text format and arguments and concats an line-break at the end into the output. |
| WriteLineAsync(IFormatProvider?, string, params object?[]) | Writes the text format and arguments and appends a line-break at the end into the output, using the specified format provider. |
| WriteLineInternal(string) | Intercepts the line that will be written to an output log before being queued for writing. This method will block if the log queue is full. |
| WriteLineInternal(LogStreamEntry) | Intercepts the specified log entry and writes it synchronously to the log stream. |
| WriteLineInternalAsync(LogStreamEntry) | Intercepts the specified log entry and writes it asynchronously to the log stream. |
| WriteLineInternalAsync(string) | Intercepts the line that will be written to an output log before being queued for writing. |