Hello
If the log file is stored/created in ,ProgramData\BlaBla\BlaBla', then only the current user has write permissions. However, if executed by another user, the program will fail logging for this user.
Is it possible to set write permission for all users with NLog or how do you solve this Problem?
I think this should be solved with the NTFS rights.
You can of course change the user of the application pool (IIS) or service
Yes - If I grant the user group 'All Users' permission to write it works. But I must always do when a new log file is created - otherwise it will not work if another user logs on to the desktop. Is there a possibility to register when NLog creates a new file so that I can grant the Access rights? (Or should I use FileSystemWatcher?)
This isn't possible in NLog. I'm curious how you would like to configure this? (Xml example?)
That would help implementing it. Or just create a PR ;)
We can not fix this without more information. So closing for now. Feel free to reopen.
I'm commenting because I think this should be implemented, even tho I found a workaround for my scenario.
I am using NLog in an WPF application.
Logfiles for any user were stored in ProgramData/Company/App/Logs/LogFile.log. This caused AccessViolationException's when 2 different users use the application.
I solved this problem by creating a separate log folder for each user using the application in the nlog.config: fileName="${specialfolder:folder=CommonApplicationData}/App/Logs/${windows-identity:domain=False}/LogFile.Log"
After this I still experienced issues when the user runs the application in elevated permission. Their windows identity stays the same, but the files created can only be edited by an admin. So the next time the user starts the application without elevation, the user couldn't archive/write to the files.
Currently I am using this workaround to make sure all files created in the folder are accessible by all users: https://stackoverflow.com/questions/1391178/nlog-in-asp-net-what-permissions-should-the-log-file-have-archiving-issue
However, I would still propose a fix for this to be implemented. This could come in the form of a new File target attribute which will make sure any files created by NLog are accessible to all users.
Example:
<target xsi:type="File"
filePermissions="allUsers | currentUser" />
@JoasE Think we back at #1249 where one could setup a WrapperTarget around the FileTarget. This custom WrapperTarget would hook into the FileTarget events. And do its Ntfs-permission-magic when needed.
This WrapperTarget could then live in its own nuget-package, one could have a Windows- and Linux-edition of the target.
Pull-Request for extending FileTarget with with file-event-notifications are always welcome. Then you can build your own custom WrapperTarget that makes use of these event-notifications, so your dreams can come true.