views:

138

answers:

3

Short: What's the most appropriate folder for windows service to dump log files into?

Details

I have a windows service that produces log files that a low-tech end user might be interested to look at (actual communication between a computer and a manufacturing line monitoring sensors).

The computer is a stand-alone dedicated computer that acts as a data acquisition server, it has monitor and accessible to the end user, but not meant to be touched unless there are problems.

What's the best (most appropriate) place (folder) to output those log files to?

My considerations are:

  1. ease of configuration (in case I have to give an access for local services account to that folder).
  2. ease of access for an end user (again: they shouldn't need to, but occasionally they might want to).

EDIT: It creates about 10 up to 1Mb rolling size files. There is no issue with size, so no compression and clean-up is necessary.

+1  A: 

Well, I'd say where your service installed to, in a /Logs/ folder. Then add functionality to compress these files at a later stage.

By doing this, you're not splitting up your applications data from the actual running application. For instance, saving this to C:\LogDumps\ gives no indication of what program created the files in the first place and would be a nightmare to maintain.

Kyle Rozendo
If I'm installing the service in the Program Files directory, I would be reluctant to give 'Local Service' write access to anything in the 'Program Files'. C:\LogDumps might be bad for the same reason, since I expect the service to be able to create lowest-level folder if it's missing.
You're not giving permissions to Program Files. You're giving permissions to the folder within your folder, within program files. If you keep the permissions only to the log folder, only the log folder can be accessed.
Kyle Rozendo
As I said "I would be reluctant to give 'Local Service' write access to anything in the 'Program Files'", my understanding that's what "Application Data" directory was meant for - to avoid programs having to write in the Program Files, so that Program Files is only for program installation, and installation-level configuration.
Personally I don't like that. That is not ideal/convenient for users to look in, and although it would be under your application in Application Data, it still hides the logs from plain sight.
Kyle Rozendo
Also there is a chance end-user willing to look at the logs files might not have permission to get into "Program Files" (not even to read).
A: 

I think the most intuitive place to log is a sub-folder "Logs" within the folder where the service is installed. For example, if the service is installed here:

c:\program files\my company\my service\

Put the logs here:

c:\program files\my company\my service\logs\

I don't like it when applications log to the "Documents and Settings" or "My Documents" areas - I don't like having crap that I didn't create in a folder that is supposed to be My Documents.

Andy White
Identical to what I said ;)
Kyle Rozendo
The reason some apps write to the Documents and Settings area is that the permissions are less restrictive there depending on the owner of the running service process.
Joe
My Documents is not a good option, since user "Bob" will have different "My Documents" location than a user "Local Service" (account under witch windows service is running).
Windows services do not have to run under "local service".
Joe
@Kyle - oops, sorry about that. I voted you up!
Andy White
+1  A: 

My preference is to make use of the All Users folder structure. By creating a folder in there with the same name as your service app, it's readily apparent where the contents come from, you can grant access to it without compromising the Program Files folder, and when you uninstall or upgrade your app you won't leave 'orphan' folders in Program Files that couldn't be removed because the installer didn't know it had to delete some log files.

Jonners
Good point. At the moment I'm doing:Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "/My Service/Logs"