Log file
-
Hi I want to write a message to the text file as soon as the server starts.I have written the following code which creates a new file but it does not write anything into it.I tested this code by starting only one server.It does not work.Please help me find where i went wrong.proclist contains the list of all servers.
foreach (Process pr in proclist)
{
if (!File.Exists("logfile.txt"))
{
stw = new StreamWriter("logfile.txt");
}
else
{
stw = File.AppendText("logfile.txt");} DateTime started = pr.StartTime; stw.WriteLine("Server information:"); stw.WriteLine(started.ToString()); }
-
Hi I want to write a message to the text file as soon as the server starts.I have written the following code which creates a new file but it does not write anything into it.I tested this code by starting only one server.It does not work.Please help me find where i went wrong.proclist contains the list of all servers.
foreach (Process pr in proclist)
{
if (!File.Exists("logfile.txt"))
{
stw = new StreamWriter("logfile.txt");
}
else
{
stw = File.AppendText("logfile.txt");} DateTime started = pr.StartTime; stw.WriteLine("Server information:"); stw.WriteLine(started.ToString()); }
-
Hi, stw.Close(); ?? or possibly stw.Flush(); stw.Close(); Although it might be simpler to forget the StreamWriter and use File.AppendAllText("logfile.txt", String.Format("Server Info:\r\n {0}\r\n", started)); Alan.
-
Hi, stw.Close(); ?? or possibly stw.Flush(); stw.Close(); Although it might be simpler to forget the StreamWriter and use File.AppendAllText("logfile.txt", String.Format("Server Info:\r\n {0}\r\n", started)); Alan.