views:

58

answers:

8

I am working on a WinForm application, that allows working to work with "projects" (think about the application as Visual Studio, and projects as VS Solutions).

My question is - where should the application keep its logging files?

Some requirements include:

  • the application might not be running as an administrator (so saving in the %ProgramFiles% installation folder is not a good option)
  • The logs should be accessible to end-users (either for review, or for sending to the support team). (This means that hard to find folders, like %AppData%\Company\Application\Version\ProjectName... are not a good solution either)
  • The application might generate logs even when there are no open projects (so saving the logs in the project's folder is good only when there's a project, but not a final solution).

I was thinking of creating a "working folder" when the application is installed - something along the lines of C:\Application\, and then save the logs in a subfolder, like %WorkingFolder%\Logs\ProjectName

Thanks for the input.

+3  A: 

Somewhere in the user's directory is actually the correct place to store them if they are specific to the current running user.

Some programs create folders at the top level of the User's directory, next to Documents and Desktop, others do it in Documents.

Creating it in C:\ might cause issues if the user doesn't have write access to the root directory. You can pretty much guarantee the user will have write access to the Home directory.

The other option is to look for an environment variable, and if its set use the value as the location, if not default to the User's home directory.

Michael Shimmins
I have run into issues with this myself. I use XP, so I didn't realize the issues initially with how vista handles permissions. You should use the user directory for anything the program will have to read/write during operation.
MaQleod
Alternatively, if the logs are not user-specific, they could go in the "all users" application data directory.
CodeSavvyGeek
A: 

You can always ask the user to configure this. Set a default path, maybe the application directory. During installation or while setting up the application you may prompt the user to input the path they want to use for logs. That's fair, right. If they're advanced enough to use logs they're good enough to configure a path too.

Sidharth Panwar
Unfortunately, the users often are not that advanced, and that is why I, as a developer, want to keep logs. Then I can tell what really happened as compared to the user's description.
cdkMoose
Fair enough. I'd suggested you keep it in Logs folder inside the app directory and create a shortcut to the logs folder inside your apps Program directory or inside your app itself. I think this should be neat. This will alleviate the restriction of choosing a static path always. You may change path in future and user wouldn't be affected.
Sidharth Panwar
A: 

I'd suggest adding that question to the installer so that the user that installs the software can decide where best to put the logs. Though C:\[AppName\ sounds like a reasonable default for your requirements.

Edit: Just thought off, it would probably be worth warning the user if the select a bad location (in Program Files or in the root of the system drive etc) and if they choose to create a new directory, automatically give that directory correct permissions during the installation.

ho1
A: 

What do you plan to do with the logs. Are they technical, of for financial/security audits?

The EventLog is a nice place for technical logs, because you can access it remotely (within the Domain) and it is cleaned up automatically.

The %AppData% is also a good place for technical logs, specially if you are unable to connect to the eventlog. You can find the log files, and you can direct the end-user to them, but they are not "in the face" of the end-user. You can include a "send log to the maker" button to receive them.

For logs that needs be accessed by end-users, the My Documents (or a subfolder) looks good.

GvS
@GvS I would make a comment on storing Logs inside of EventLog, sometimes people don't realize that they are writing to it so frequently that they fill it up. Which if not expected causes other issues. I like using it for truly exceptional cases and leave ones that I want to log and expect to be logging to a log file.
msarchet
A: 

You can just to add button / menu item to easy open folder with logs. Best place fo logs are %AppData%\AppName or %temp%\AppName. Never use %MyDocs% or %Program Files%.

evg345
A: 

I think %APPDATA%\YourCompanyName\YourAppName is the preferred location. To overcome your stated objection of this location being hard to find, you could pretty easily and quickly implement a simple support screen in your app to allow the end user the ability to access and email these logs without too much trouble, so that the user will not have to remember or manually navigate to the long path name to get to the logs.

I don't really like the idea of the user being able to set this location via the installer because of possible naming and permission issues.

PaulR
A: 

If the app needs to maintain the log only for the users current logged in timespan, then you could keep it in c:/temp.

Most of my winapps, i leave it there, so automatically it gets deleted once the user logs off..

Ofcourse, this primarily depends on your requirement.

srivatsayb
+2  A: 

If the logs are user only you should store them at %AppData%\Company\Application Name.

If the logs are shared (any user can see any log) you should store them at:
%ProgramData%\Company\Application Name (for Vista+)
or
%AllUsersProfile%\Application Data\Company\Application Name (for XP-)

As for user access, you can add a shortcut to the start menu to the appropriate location or have a link within the program.

Another option in Vista+ is the Public folder (%Public%) which has links throughout Explorer for easy access to.

Where should I write program data instead of Program Files is a good blog entry by Chris Jackson from Microsoft. While it isn't an "official stance" it holds some excellent information.

Joshua