Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the best locations to write an error log in Windows?

Where would you write an error log file, say ErrorLog.txt, in Windows? Keep in mind the path would need to be open to basic users for file write permissions.

I know the eventlog is a possible location for writing errors, but does it work for "user" level permissions?

EDIT: I am targeting Windows 2003, but I was posing the question in such a way as to have a "General Guideline" for where to write error logs.
As for the EventLog, I have had issues before in an ASP.NET application where I wanted to log to the Windows event log, but I had security issues causing me heartache. (I do not recall the issues I had, but remember having them.)

like image 939
Keith Sirmons Avatar asked Oct 10 '08 14:10

Keith Sirmons


2 Answers

The standard location(s) are:

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

or

C:\Documents and Settings\%Username%\Application Data\MyApp

(aka %UserProfile%\Application Data\MyApp) which would match your user level permission requirement. It also separates logs created by different users.

Using .NET runtime, these can be built as:

AppDir=
  System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

or

AppDir=
  System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

followed by:

MyAppDir = IO.Path.Combine(AppDir,'MyApp')

(Which, hopefully, maps Vista profiles too).

like image 148
gimel Avatar answered Sep 19 '22 21:09

gimel


Have you considered logging the event viewer instead? If you want to write your own log, I suggest the users local app setting directory. Make a product directory under there. It's different on different version of Windows.

On Vista, you cannot put files like this under c:\program files. You will run into a lot of problems with it.

In .NET, you can find out this folder with this:

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

And the Event Log is fairly simple to use too:

http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx

like image 28
Lou Franco Avatar answered Sep 20 '22 21:09

Lou Franco