异常日志文件的最佳位置 (Windows)

发布于 2024-07-11 13:17:46 字数 456 浏览 2 评论 0原文

异常日志应该放在哪里的问题已经在这里讨论过一两次(或多次),其中一个建议是应用程序永远不应该写入安装文件夹。
但是,如果我将日志放在 %appdata% 中的某个位置,这意味着每个用户都有自己的一组日志。 我更喜欢将所有日志放在一个位置。
在最新的 MSDN mag 问题之一中,安装文件夹中具有单独的日志子文件夹(例如 %programfiles\myapp\logs)被称为规则的有效例外。 当然,必须相应地设置该文件夹的 ACL。
在安装文件夹中放置日志文件夹是常见做法还是绝对不行? 您将异常日志放在哪里?

编辑:
事实上,我们使用的是 log4net,因此日志记录的位置和类型是完全可配置的。 但是,我想要一个合理的默认值。 我更喜欢使用文件而不是事件日志。 对于大多数用户来说,文件比事件日志更容易处理。
但是,假设我想要文件。 安装文件夹中可以有一个日志文件夹吗?

The question where exception logs should go has been discussed here once or twice (or more), and one of the recommendation was that the application should never write to the installation folder.
However, if I put the logs somewhere in %appdata%, this means that each user has its own set of logs. I'd prefer having all logs at a single location.
In one of the last MSDN mag issues, having a separate sub folder for logs in the installation folder (e.g. %programfiles\myapp\logs) was called a valid exception from the rule. Of course, the ACL for this folder must be set up accordingly.
Is having a log folder in the installation folder common practice or an absolute no-go? Where do you put your exception logs?

Edit:
In fact, we are using log4net, so the location and type of logging is completely configurable. However, I want to have a reasonable default.
I prefer having a file over the event log. For most users, a file is much easier to handle than the event log.
However, let's assume that I want to have files. Is it okay to have a log folder in the installation folder?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

似最初 2024-07-18 13:17:46

对于较新的操作系统 vista 和 win 2008,写入程序文件目录可能需要 ACL 或虚拟化到用户的文件夹。 我建议在 %AllUsersProfile% 下设置一个目录,这样您就可以为所有用户的日志文件提供一个通用位置,并且您的应用程序不需要以管理员身份运行来将它们写入那里。

With the newer OS vista and win 2008 writing to the program files directory may need ACL or be virtualized to the user's folder. I would suggest setting up a directory under %AllUsersProfile% this way you have one common location for all user's log files and your applications does not need to run as admin to write them there.

私野 2024-07-18 13:17:46

如果您不能或不会使用事件日志,那么日志文件的放置位置确实没有任何标准化。 您只需要确保该位置有详细记录,并且代码中确实需要有逻辑来确保日志文件可以增长到的大小有限制。

If you cannot or won't use the event logs, then there really isn't any standardization on where to put the log file. You just need to be sure that the location is well documented and there really needs to be logic in your code to be sure that there is a limit on the size that the log file can grow to.

终止放荡 2024-07-18 13:17:46

这主要取决于应用程序,这就是为什么我猜有这么多可能的答案。

对于网站,我会在服务器上有一个“C:\log”,然后对于各个网站有一个“C:\log\website”,并使用 Log4Net 或类似的。

对于 Web 服务、窗口服务、计划作业等,我会写入 Windows 事件日志。 我的电脑 -> 管理-> 系统工具-> 事件视图-> (我的服务)

对于部署在我控制的环境中的 Windows 应用程序(即公司内部应用程序),我将通过电子邮件将异常报告发送给“IT 团队”。

对于分发给未知用户的 Windows 应用程序。 没做什么。

It depends mainly on the application, which is why I guess there are so many possible answers.

For websites, I would have a "C:\log" on the server, then "C:\log\website" for individual websites and use Log4Net or similar.

For web services, window services, scheduled jobs etc, I would write to the Windows Event Log. My Computer -> Manage -> System Tools -> Event View -> (My Sevice)

For a windows application which is deployed in an environment I control (i.e. internal company application) I woudl have it email "the IT team" exception reports.

For a windows application which is distrobuted to unknown users. Do nothing.

时常饿 2024-07-18 13:17:46

您需要注意写入日志文件夹的权限。

这是使用应用程序数据文件夹而不是安装文件夹的关键原因之一,因为在 Vista 及以后的版本中,默认情况下您可能无权写入安装文件夹。

You'll want to watch out for permissions to write to the log folder.

This is one of the key reasons to use the application data folder instead of the install folder, because in Vista and moving forward, by default you probably won't have access to write to the install folder.

橙味迷妹 2024-07-18 13:17:46

我认为您应该更喜欢 AppData 文件夹,但如果您想将所有日志合并在一个文件夹中,请使用所有用户目录 (Environment.SpecialFolder.CommonApplicationData) 并在应用程序文件夹内为每个用户创建子文件夹。 通过这种方式,您不仅可以摆脱权限问题,还可以避免弄乱您自己的空间:) 恕我直言。

I think You should prefer the AppData folder but if you want to combine all the logs in one folder then use All Users Directory ( Environment.SpecialFolder.CommonApplicationData) and create sub folders inside your app folder for each user. In this way you not only get rid of permission issues but also avoid cluttering your own space :) IMHO.

顾挽 2024-07-18 13:17:46

对于 Windows,请使用事件日志。 创建您自己的日志非常容易,或者您只需将消息添加到标准日志之一即可。

这样做的好处是,当事情进展不顺利时,地球上几乎所有技术人员(和程序员)都希望在事件日志中显示一些内容。

For windows, use the event log. It's pretty easy to create your own log or you can just add your messages to one of the standard ones.

This has the benefit that nearly every tech (and programmer) on the planet expects something to show up in the event log when things aren't going right.

路弥 2024-07-18 13:17:46

要登录到没有特殊 ACL 的通用文件,请使用类似

string saveFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\MyCompany";

引用文件夹的

C:\Documents and Settings\All Users\Application Data\MyCompany

在XP 上

C:\ProgramData\MyCompany

内容,以及在 Vista 下使用类似的内容。 您需要在某个时刻(也许是在应用程序启动时)验证该文件夹是否存在。

For logging to a common file without special ACLs, use something like

string saveFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\MyCompany";

which references the folder in

C:\Documents and Settings\All Users\Application Data\MyCompany

on XP, and something like

C:\ProgramData\MyCompany

under Vista. You'll need to verify that the folder exists at some point - perhaps at application startup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文