Console.SetOut : Console « System « C# / C Sharp by API






Console.SetOut

  
using System;  
using System.IO; 
  
public class Redirect { 
  public static void Main() { 
    StreamWriter log_out; 
 
    try { 
      log_out = new StreamWriter("logfile.txt"); 
    } 
    catch(IOException exc) { 
      Console.WriteLine(exc.Message + "Cannot open file."); 
      return ; 
    } 
    
    Console.SetOut(log_out); 
    Console.WriteLine("This is the start of the log file."); 
 
    for(int i=0; i<10; i++) Console.WriteLine(i); 
 
    Console.WriteLine("This is the end of the log file."); 
    log_out.Close(); 
  } 
}

   
    
  








Related examples in the same category

1.Console.BackgroundColor
2.Console.Beep()
3.Console.Beep(200, 300)
4.Console.BufferHeight
5.Console.BufferWidth
6.Console.Clear()
7.Console.CursorLeft
8.Console.CursorSize
9.Console.CursorTop
10.Console.CursorVisible
11.Console.ForegroundColor
12.Console.In
13.Console.Out
14.Console.Read()
15.Console.ReadLine()
16.Console.ResetColor()
17.Console.SetWindowSize
18.Console.Title
19.Console.Write
20.Console.WriteLine