0

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.

shujaat siddiqui
  • 1,527
  • 1
  • 20
  • 41

2 Answers2

1

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:

http://malor.se/blog/?p=23

toATwork
  • 1,335
  • 16
  • 34
0

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.

schglurps
  • 1,387
  • 1
  • 14
  • 26