-3

I have a winform application that sometimes needs to log info to a local file when connection to service is broken. After reconnect all log files will be sent to the service for logging in database. Because the log is stored in the root of the application folder it can be read by other user accounts of the computer. So if user A that gets an exception do not have connection to the service the content of the logfile from user A will be sent when user B connects to the service.

The problem is that some users to not give write permissions to the root folder.

There is special user folders that could be used but the problem is that user B will not be able to send user A log file to service.

Is there any shared Windows folder where I always can write? Or do I have to require write permission of the root of the application?

Regards

Banshee
  • 15,376
  • 38
  • 128
  • 219
  • Maybe `System.IO.Path.GetTempPath()`? – Klamsi Jun 15 '21 at 09:28
  • @Klamsi writting in temp path is risky if you want the data to remain so logs can be checked. Windows integrated disk free space tool could delete the files from the TempPath. – Cleptus Jun 15 '21 at 10:01
  • As far I understood local logs are just temporary "when connection to service is broken" until "After reconnect all log files will be sent to the service for logging in database. ". But yes, you are right, there's no guarantee that they are still here. – Klamsi Jun 15 '21 at 10:03
  • The standard is: *User Temp Path* if temporary for the process execution session or `%USER%\AppData\Roaming\Company\Application\Log` or `%USER%\Documents\Roaming\Company\Application\Log` or `%PROGRAMDATA%\Company\Application\Log` to be shared. See [Work with user paths](https://stackoverflow.com/questions/58202091/how-to-keep-the-last-used-folder-and-put-it-in-a-textbox-when-a-form-opens/58202264#58202264) –  Jun 15 '21 at 10:56

1 Answers1

1

If you want to write logs for the per User that the application is started as, I would write them in AppData, but if you want to store logs that is global to your application I would write the logs in ProgramData.

In C# you can get these special folders with Environment.GetFolderPath and passing as an argument the desired Environment.SpecialFolder.

Cleptus
  • 3,446
  • 4
  • 28
  • 34
A. Boz
  • 132
  • 1
  • 8
  • Okay, so in this vase the Environment.SpecialFolder.CommonApplicationData would be a good choise? – Banshee Jun 15 '21 at 09:44
  • Probably A. Boz is suggesting `SpecialFolder.ApplicationData` instead (the folder you get when in the explorer you type `%AppData%`). The `CommonApplicationData` I believe is used for data shared between different applications. – Cleptus Jun 15 '21 at 09:47
  • From what I can read the ApplicationData is per-user while CommonApplicationData is the same but across users. So in my case it sounds like I should use CommonApplicationData. – Banshee Jun 15 '21 at 09:58