I have built a service on a windows server 2008 R2 server that executes a windows forms application. That is all working but when I want to write an error to the log on a shared network location i get the error.
But the weird thing is that when I execute the executable from the windows forms project as administrator it's working, but when I run the service under a administrator account i get the error .
This is the code how I write to the log file So i first try to write to L:\ and when that's not working I write in C:\ what is working
Try
Using writer As StreamWriter = New StreamWriter("L:\subfolder\subfolder\log.txt", True)
writer.WriteLine(Now & " - project started. Build 7-12-2012")
End Using
Catch ex As System.Exception
Using writer As StreamWriter = New StreamWriter("c:\subfolder\log.txt", True)
writer.WriteLine(Now & " - ERROR " & ex.ToString)
End Using
Finally
End Try
Mapped drives are often user and session dependent, so while you are running the program on the desktop, drive L exists, but when running as a service, its likely drive L was not mapped and doesn't exist. I suggest using the full network path, like \\servername\sharedfolder\...