Redirect Console.Out : Console Redirect : Development C# Examples


C# Examples » Development » Console Redirect »

 

Redirect Console.Out









    
using  System;    
using  System.IO;  
    
class  MainClass  {  
    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.");  
  
        log_out.Close();  
    }  
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» Console Redirect