public static void WriteLogFile(string message)
{
Console.WriteLine(message);
if (File.Exists("C:\\log.txt"))
{
using (StreamWriter SWriter = File.AppendText("C:\\log.txt"))
{
SWriter.WriteLine(message);
}
}
else
{
using (StreamWriter SWriter = File.CreateText("C:\\log.txt"))
{
SWriter.WriteLine(message);
}
}
}

Suthish NairRank #92 · 22.8K reputationPosted Apr 17, 2014, 6:58 AM EDT
Princy GuptaRank #1,602 · 982 reputationPosted Apr 17, 2014, 9:52 PM EDT
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Apr 17, 2014, 11:01 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 18, 2014, 12:05 AM EDT
hi,
Are you getting this error every time?
VulpesRank #55 · 29.2K reputationPosted Apr 18, 2014, 1:19 AM EDT
If you're attempting to write to a file on the root C: drive, try 'run as administrator' or (better) create a folder off the root and then write to that.