Reputation: 1587
I have a application in which i am implementing log4net.dll
. i installed this application on different computers and its working fine.
my application installs at C:\ProgramFile\myApplication.
However the problem is when the user does not have write permission on under ProgramFile. It does not write a log ?
I am wondering is there any way that i could assign all access permission the folder during installation. I went through different articles but could not find any satisfactory answer.
Any help would be appreciated.
Upvotes: 0
Views: 183
Reputation: 1377
You should not put your log files in the (sub)folder of your application! Put them where it is certain that every user has write permissions, e.g. $Appdata or $LocalAppdata (which I prefer for log files)
Example for log4net config:
<file value="${APPDATA}/My Company/My Product/Logs/My Application.log" />
taken from here:
Upvotes: 1
Reputation: 1387
I worked on a similar problem within a WIX installer, here is the code :
DirectoryInfo directoryInfo = new DirectoryInfo(session["..."]);
DirectorySecurity directorySecurity = directoryInfo.GetAccessControl();
SecurityIdentifier localService = new SecurityIdentifier(WellKnownSidType.LocalServiceSid, null);
FileSystemAccessRule directoryAccessRule = new FileSystemAccessRule(localService, FileSystemRights.FullControl, AccessControlType.Allow);
directorySecurity.AddAccessRule(directoryAccessRule);
directoryInfo.SetAccessControl(directorySecurity);
The Local Service account is granted full access to a folder. Just change the SID of the Local Service user by the SID of the user who will use your application.
Upvotes: 0