C# console application log file
In a C# 2008 console application, the log file must be redirected to a dos popup window since that is what I see in the dos popup window. I do not see any kind of log files being saved. Thus can you tell me how to change code that goes to the dos popup menu and have the results saved to a log file instead?
VulpesPosted Sep 1, 2012, 2:42 PM
using System;
using System.IO;
class Test
{
static void Main()
{
Console.WriteLine("Standard output");
FileStream fs = new FileStream("test.log", FileMode.Append);
TextWriter standard = Console.Out; // save standard output
using (StreamWriter sw = new StreamWriter(fs))
{
Console.SetOut(sw); // redirect output to file
Console.WriteLine("First entry");
Console.WriteLine("Second entry");
}
fs.Close();
Console.SetOut(standard); // cancel redirection
Console.WriteLine("Standard output again");
Console.ReadKey();
}
}
dcPosted Sep 1, 2012, 1:37 PM
Venkatesh KumarPosted Sep 1, 2012, 1:17 PM