Class TeeTextWriter
TextWriter that writes to both the original console output and a log file simultaneously. This allows AI tools to read the log file and understand what happened during the last application run. The file is overwritten on each new run.
public class TeeTextWriter : TextWriter, IAsyncDisposable, IDisposable
- Inheritance
-
TeeTextWriter
- Implements
- Inherited Members
- Extension Methods
Constructors
TeeTextWriter(TextWriter, string)
Initializes a new TeeTextWriter that writes to both the original writer and a log file.
public TeeTextWriter(TextWriter originalWriter, string logFilePath)
Parameters
originalWriterTextWriterOriginal text writer to tee from.
logFilePathstringPath to the log file.
Properties
Encoding
When overridden in a derived class, returns the character encoding in which the output is written.
public override Encoding Encoding { get; }
Property Value
- Encoding
The character encoding in which the output is written.
OriginalWriter
The original TextWriter that was wrapped. Used to restore Console.Out/Error after logging is done.
public TextWriter OriginalWriter { get; }
Property Value
Methods
Dispose(bool)
Releases the unmanaged resources used by the TextWriter and optionally releases the managed resources.
protected override void Dispose(bool disposing)
Parameters
disposingbooltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
FinalizeLog()
Writes a final footer to the log file and restores the original console writer
public void FinalizeLog()
Flush()
Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
public override void Flush()
FlushAsync()
Asynchronously clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
public override Task FlushAsync()
Returns
- Task
A task that represents the asynchronous flush operation.
Exceptions
- ObjectDisposedException
The text writer is disposed.
- InvalidOperationException
The writer is currently in use by a previous write operation.
Write(char)
Writes a character to the text stream.
public override void Write(char value)
Parameters
valuecharThe character to write to the text stream.
Exceptions
- ObjectDisposedException
The TextWriter is closed.
- IOException
An I/O error occurs.
Write(string?)
Writes a string to the text stream.
public override void Write(string? value)
Parameters
valuestringThe string to write.
Exceptions
- ObjectDisposedException
The TextWriter is closed.
- IOException
An I/O error occurs.
WriteAsync(char)
Writes a character to the text stream asynchronously.
public override Task WriteAsync(char value)
Parameters
valuecharThe character to write to the text stream.
Returns
- Task
A task that represents the asynchronous write operation.
Exceptions
- ObjectDisposedException
The text writer is disposed.
- InvalidOperationException
The text writer is currently in use by a previous write operation.
WriteAsync(string?)
Writes a string to the text stream asynchronously.
public override Task WriteAsync(string? value)
Parameters
Returns
- Task
A task that represents the asynchronous write operation.
Exceptions
- ObjectDisposedException
The text writer is disposed.
- InvalidOperationException
The text writer is currently in use by a previous write operation.
WriteLine()
Writes a line terminator to the text stream.
public override void WriteLine()
Exceptions
- ObjectDisposedException
The TextWriter is closed.
- IOException
An I/O error occurs.
WriteLine(string?)
Writes a string to the text stream, followed by a line terminator.
public override void WriteLine(string? value)
Parameters
Exceptions
- ObjectDisposedException
The TextWriter is closed.
- IOException
An I/O error occurs.
WriteLineAsync()
Asynchronously writes a line terminator to the text stream.
public override Task WriteLineAsync()
Returns
- Task
A task that represents the asynchronous write operation.
Exceptions
- ObjectDisposedException
The text writer is disposed.
- InvalidOperationException
The text writer is currently in use by a previous write operation.
WriteLineAsync(string?)
Asynchronously writes a string to the text stream, followed by a line terminator.
public override Task WriteLineAsync(string? value)
Parameters
Returns
- Task
A task that represents the asynchronous write operation.
Exceptions
- ObjectDisposedException
The text writer is disposed.
- InvalidOperationException
The text writer is currently in use by a previous write operation.