在 Windows 上存储应用程序日志文件的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1572934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:50:11  来源:igfitidea点击:

Where to store an application log file on Windows

windowslogging

提问by Darcy Casselman

Where would be the best "standard" place to put an application's debug log file in a Windows user environment?

将应用程序的调试日志文件放在 Windows 用户环境中的最佳“标准”位置在哪里?

In this particular case, it is an application that is run once and could go wrong. It will be run by system administrator types who may need to inspect the log after the application is run. Everytime the application is run, a new log file is created.

在这种特殊情况下,它是一个运行一次并且可能出错的应用程序。它将由系统管理员类型运行,他们可能需要在应用程序运行后检查日志。每次运行应用程序时,都会创建一个新的日志文件。

Options that have been floated so far include:

到目前为止已经浮动的选项包括:

  1. The program directory
  2. The user's desktop
  3. The user's local Application Data directory.
  1. 程序目录
  2. 用户的桌面
  3. 用户的本地应用程序数据目录。

I have my favourite, but I wondered what the SO consensus was.

我有我最喜欢的,但我想知道 SO 共识是什么。

Note: this is similar to this question, but we're dealing with an application that's only likely to be run once by one user.

注意:这类似于这个问题,但我们正在处理一个应用程序,它可能只由一个用户运行一次。

采纳答案by Mark Ransom

The Application Data directory would seem to be the perfect place, but it's an area that is nearly invisible. You need to give your users an easy way to get to it.

Application Data 目录似乎是一个完美的地方,但它是一个几乎不可见的区域。您需要为您的用户提供一种轻松访问它的方法。

Have your installation script create a Log folder in the Application Data area for your program, and include a link to the folder in your Start menu.

让您的安装脚本在应用程序数据区域中为您的程序创建一个日志文件夹,并在您的开始菜单中包含一个指向该文件夹的链接。

回答by GoJiTa972

In the organization I work for we use the (%TEMP% or %TMP%)\CompanyOrProductName\Logs directory Using %APPDATA% may be problematic with roaming profiles if the logs are numerous or huge : it slows their login process ...

在我工作的组织中,我们使用 (%TEMP% 或 %TMP%)\CompanyOrProductName\Logs 目录如果日志数量众多或巨大,则使用 %APPDATA% 可能会对漫游配置文件产生问题:它会减慢他们的登录过程......

回答by James

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. Even in the MyDocuments of the user would be a good shout.

日志的“标准”位置是 AppData 目录。但是,实际上取决于您想将它们存储在何处。由于他们是管理员(高级用户),因此将日志存储在与正在运行的应用程序相同的目录中应该没有问题。即使在 MyDocuments 中的用户也会很好的喊叫。

回答by DmitryK

1.The program directory <- not good. Ideally you will only have RX permissions on this folder.

1.程序目录<-不好。理想情况下,您对该文件夹只有 RX 权限。

2.The user's desktop <- technically can be done, but I don't like this idea. Polluting desktop... I, as a user, don't like it.

2.用户的桌面<-技术上可以做到,但我不喜欢这个想法。污染桌面...作为用户,我不喜欢它。

3.The user's local Application Data directory. <- better

3.用户的本地应用程序数据目录。<- 更好

My preference is a subdirectory under the program directory (with a clear name like "DebugLog" or something similar). Permissions on that subdirectory should allow creating and writing files ("Change" will be fine)

我的偏好是程序目录下的子目录(具有明确的名称,如“DebugLog”或类似名称)。该子目录的权限应该允许创建和写入文件(“更改”就可以了)

回答by Foxfire

If you EXPECTsomething to go wrong put it in the user's local Application Data directory.

如果您希望出现问题,请将其放在用户的本地应用程序数据目录中。

If you don't and just want to log anyways I might think about really using the temp directory. The reasoning for this is simple. If the application is only run once you will leave trash in the Application Data directory otherwise that nobody will ever need again. In the temp you have at least the CHANCE that it's going to be cleaned up later.

如果您不这样做并且只想登录,我可能会考虑真正使用临时目录。原因很简单。如果应用程序只运行一次,您将在应用程序数据目录中留下垃圾,否则没有人会再次需要它。在临时情况下,您至少有机会稍后对其进行清理。

BTW: IMHO the best would be not not create the log AS A FILE at all (log to memory) until something goes wrong. Then you can still offer a dialog where the user selects where to save the log.

顺便说一句:恕我直言,最好不要在出现问题之前根本不将日志创建为文件(记录到内存)。然后您仍然可以提供一个对话框,用户可以在其中选择保存日志的位置。

回答by Zote

Windows Temp Folder

Windows 临时文件夹

回答by cdiggins

Assuming you want to keep log files around a significant amount of time and they are intended to be used, read I would put the log file in a sub-folder of the user's local application data folder, accessible from windows explorer by typing %localappdata%.

假设您希望将日志文件保留大量时间并且打算使用它们,请阅读我会将日志文件放在用户本地应用程序数据文件夹的子文件夹中,通过键入%localappdata%.

If they are temporary log files, only to be used in the event of system diagnostics then you should put them in the temporary folder, accessible from windows explorer %temp%.

如果它们是临时日志文件,仅在系统诊断时使用,那么您应该将它们放在临时文件夹中,可从 windows 资源管理器访问%temp%