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);
}
}
}
5 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Apr 18, 2014, 5:19 AM
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.
Jignesh TrivediPosted Apr 18, 2014, 4:05 AM
hi,
Are you getting this error every time?
Lakshmanan Sethu SankaranarayanPosted Apr 18, 2014, 3:01 AM
Princy GuptaPosted Apr 18, 2014, 1:52 AM
Suthish NairPosted Apr 17, 2014, 10:58 AM