Redirects Console.Out to the specified TextWriter. By default, Console.Out is set to the system's standard output stream.
[Visual Basic] Public Shared Sub SetOut( _ ByVal newOut As TextWriter _ ) [C#] public static void SetOut( TextWriter newOut ); [C++] public: static void SetOut( TextWriter* newOut ); [JScript] public static function SetOut( newOut : TextWriter );
Exception Type | Condition |
---|---|
ArgumentException | newOut is null. |
SecurityException | The caller does not have SystemStreamsPermission to set the standard error stream. |
A StreamWriter that encapsulates a FileStream can be used, in order to send output to a file.
In multi-threaded programs, an application getting the exception IndexOutOfRangeException with an exception message about "Probable IO race condition detected while accessing a file or Console...", must be updated to use thread-safe console output. To do this, simply synchronize the console. Here's an example:
Console.SetOut(StreamWriter.Synchronized(Console.Out));
The caller must have SystemStreamsPermission to set the standard output stream.