Jason Stevens
Jason Stevens

Reputation:

Where should I store my log file so a user has write permissions to it?

I currently store my log file in the Program Files\My App folder but some users don't have permission to write here if they are not a power user or administrator. Is there a common location for this type of log file?

Update:

I'm currently using Application.StartupPath.

logFileLocation = System.Windows.Forms.Application.StartupPath;

Upvotes: 2

Views: 491

Answers (3)

Rob Kennedy
Rob Kennedy

Reputation: 163287

Instead of writing to a log file, write to the event log. It's managed by a system service, so you don't have to worry about any particular user's storage permissions. If you write to the general application event log, then your application's messages will be mixed with everything else from the system, so when you request the logs from your customer, you'll get to see what else was happening on the system when your application failed. You can also write to an application-specific event log.

Upvotes: 0

user1228
user1228

Reputation:

I'd use Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) and then Path.Combine that with ApplicationName\Version\LogFileName

Upvotes: 4

John Sibly
John Sibly

Reputation: 23076

I would use the temporary folder.

Use the function GetTempPath on the Windows API, or Path.GetTempPath in .NET

Upvotes: 0

Related Questions