PDA

View Full Version : Log file Location for Windows 7 Application



stefanadelbert
22nd July 2010, 04:50
I'm writing a Qt Application for Windows 7 and I'm currently adding a relatively crude log-to-file mechanism.


I'm using a QTextStream linked to a QFile (QIODevice::WriteOnly | QIODevice::Text) to write data to file
I'm installing a QMsgHandler using qInstallMsgHandler which appends a timestamp to the message and then writes it to file using the QTextStream
I'm planning on having the logging running in a separate thread, but I'll get to that later


For the moment, I'm stuck on where I should actually create the log file under Windows 7. I'm developing in VS 2008 and using Windows Installer to create installation packages. My Qt application installs under C:\Program Files\..., which works fine for running the application without creating the log file. But Windows is not allowing my application me to create the log file in C:\Program Files, unless I run the application as Administrator.

Is there standard pattern for this? Does Windows prefer the log files be written somewhere else (an equivalent of Linux's /var/log)?

Any help appreciated.

ChrisW67
22nd July 2010, 05:41
Applications should not write to the "Program Files" location at run time: this is blocked by Windows 7. You have a couple of options depending on what the intended use of the file is, its permanence, and how easy you want it to be found by your users. Use QDesktopServices to locate the user's documents directory or the application data/cache directory. You could also write to the system temporary directory (QTemporaryFile).

MSDN has a whole bunch of guidance on this if you want to go Windows-specific.