I have a TeamCity CI Server on a Win7 64 bit machine (running with default settings i.e. service runs in the Local System account)
As part of my code, the application creates a log file in the LocalApplicationData folder.
_logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"auction-sniper.log");
I have an acceptance test that verifies the same. The acceptance test spawns the executable and uses White v0.2 to control it. I trigger an error and verify that the log file contains the expected error.
Now when run locally (via NUnit or via Resharper5 from the IDE), all tests pass. However on the CI System, the test fails with the following error,
Test(s) failed. System.IO.FileNotFoundException : Could not find file 'C:\windows\system32\config\systemprofile\AppData\Local\auction-sniper.log'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
<snipped>
- If I try to navigate to the above folder via the file explorer, I get an access denied dialog (Run as diff user didn't work either)
- I'm not sure what the password for the localSystem account is.. Also since it is writing to the LocalApplicationData folder of the currently logged on user, I'm expecting it to have the required access permissions.
- Can't see any exceptions in the console traces..
Any ideas ?
Update: Logging in as administrator, I was able to explore the above mentioned folder. However there is no log file created there.
I added some code to the method where the log file is created and created a parallel log file in an unrestricted drive w:
public void Log(string message)
{
using (var backup = File.AppendText(@"w:\auction-sniper-copy.log"))
using (var stream = File.AppendText(_logFilePath))
{
Tracer.Log("Writing message to {0} : {1}", _logFilePath, message);
stream.WriteLine(message);
backup.WriteLine(string.Format("Writing message to {0} : {1}", _logFilePath, message));
}
}
The log file in W: now shows
Writing message to C:\windows\system32\config\systemprofile\AppData\Local\auction-sniper.log : AuctionItem 54321 : Failed! Message = This is a message that the sniper can't handle
when run via NUnit GUI
Writing message to C:\Users\Gishu\AppData\Local\auction-sniper.log : AuctionItem 54321 : Failed! Message = This is a message that the sniper can't handle
For some reason, when run in the SYSTEM account, the log file is not created/deleted somehow... as a result the FileNotFoundException is thrown.