Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best place to store configuration files and log files on Windows for my program?

Tags:

c#

windows

I need to store log files and configuration files for my application. Where is the best place to store them?

Right now, I'm just using the current directory, which ends up putting them in the Program Files directory where my program lives.

The log files will probably be accessed by the user somewhat regularly, so %APPDATA% seems a little hard to get to.

Is a directory under %USERPROFILE%\My Documents the best? It needs to work for all versions of Windows, from 2000 forward.

like image 337
Dave Avatar asked Nov 06 '08 19:11

Dave


People also ask

Where should I store my log files?

The "standard" place for the log would be the AppData directory. However, really its up to you where you want to store them. As they are administrator (power users) then there should be no problems storing the logs in the same directory as the application being run.

Where should config files be?

System-wide software often uses configuration files stored in /etc , while user applications often use a "dotfile" – a file or directory in the home directory prefixed with a period, which in Unix hides the file or directory from casual listing. Some configuration files run a set of commands upon startup.

Where are Windows configuration files stored?

This file is located in %windir%\system32\inetsrv\config.

Which folder stores configuration files?

Configuration files are normally saved in the Settings folder inside the My Documents\Source Insight folder.


2 Answers

If you're not using ConfigurationManager to manage your application and user settings, you should be. The configuration toolkit in the .NET Framework is remarkably well thought out, and the Visual Studio tools that interoperate with it are too.

The default behavior of ConfigurationManager puts both invariant (application) and modifiable (user) settings in the right places: the application settings go in the application folder, and the user settings go in System.Environment.SpecialFolder.LocalApplicationData. It works properly under all versions of Windows that support .NET.

As for log files, System.Environment.SpecialFolder.LocalApplicationData is generally the place that you want to put them, because it's guaranteed to be user-writeable.

There are certainly cases where you wouldn't - for instance, if you want to write files to a network share so that you easily can access them remotely. There's a pretty wide range of ways to implement that, but most of them start with creating an application setting that contains the path to the shared folder. All of them involve administration.

I have a couple of complaints about ConfigurationManager and the VS tools: there needs to be better high-level documentation than there is, and better documentation of the VS-generated Settings class. The mechanism by which the app.config file turns into the application configuration file in the target build directory is opaque (and the source of one of the most frequently asked questions of all: "what happened to my connection string?"). And if there's a way of creating settings that don't have default values, I haven't found it.

like image 138
Robert Rossney Avatar answered Oct 07 '22 10:10

Robert Rossney


Note: You can get the path to the LocalApplicationData folder in .NET by using the following function:

string strPath=System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData); 
like image 29
WWC Avatar answered Oct 07 '22 10:10

WWC