I have this simple code that records appends a log to a text file:
public static void RecordToFile(string filename, Log log)
{
TextWriter textWriter = new StreamWriter(Constants.APP_PATH +
"\\" + filename, true);
textWriter.WriteLine(log.ToString());
textWriter.Close();
}
This works perfectly in a Windows Forms application. However, using the instsrv and srvany trick, I made this a Windows Service. The service runs fine, accesses the database, performs queries and all… Except for this StreamWriter. The log just doesn’t get updated as it should. Any ideas why?
Most likely the service is running under user credentials that does not have access rights to that directory.
So check the properties dialog for the service, and check the Log On tab to see what it logs on as.