存储配置文件和日志在Windows文件我的程序最好的地方? [英] Best place to store configuration files and log files on Windows for my program?

查看:68
本文介绍了存储配置文件和日志在Windows文件我的程序最好的地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要存储日志文件和配置文件,我的应用程序。哪里来存储它们的最佳地点?

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

现在,我只是使用当前目录,它最终将它们在自己的程序的Program Files目录。

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

日志文件可能会被用户经常有些访问,所以%APPDATA%似乎有点难以到达。

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

是下了目录%USERPROFILE%\\我的文档最好?它需要的所有Windows版本的工作,从2000年向前。

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

推荐答案

如果你不使用 ConfigurationManager中来管理应用程序和用户设置,你应该。在.NET Framework配置工具包显着经过深思熟虑的,并与它进行互操作的Visual Studio工具也有同感。

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.

ConfigurationManager中的默认行为提出两个不变(应用程序),并在适当的地方修改的(用户)的设置:应用程序设置走在应用程序文件夹,并且用户设置进去 System.Environment.SpecialFolder.LocalApplicationData 。它正常工作,支持.NET所有版本的Windows下的。

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.

至于日志文件, System.Environment.SpecialFolder.LocalApplicationData 通常是你想要把他们的地方,因为它保证是用户可写的。

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.

有肯定,你不会的情况下 - 例如,如果你想将文件写入到网络共享,让您可以轻松地远程访问它们。有一个pretty多种方式来实现这一点,但他们大多开始创建包含路径共享文件夹的应用程序设置。所有这些都涉及管理。

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.

我有一个关于 ConfigurationManager中夫妇的投诉和VS工具:需要有比没有好高层次的文档和VS-生成更好的文档设置类。该机制,使的app.config 文件变成目标构建目录应用程序配置文件是不透明的(以及所有最常见的问题之一来源: 发生了什么事我的连接字符串?)。如果有创建没有默认值设置的一种方式,我还没有发现它。

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.

这篇关于存储配置文件和日志在Windows文件我的程序最好的地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆