nlog - Write access to the local file system inside a Visual Studio Add-In -


i developing add-in (in c#) visual studio 2012 , trying use nlog log information add-in code local log file (e.g. in same local directory add-in being loaded from). nothing being logged , when debugged things more seems not have write access local file system inside add-in code. trying open local file , write line throws system.unauthorizedaccessexception:

[system.unauthorizedaccessexception] = {"access path 'c:\\program files (x86)\\microsoft visual studio 11.0\\common7\\ide\\test.txt' denied."} 

is basic limitation add-ins? vs not allow write access local file system?

thanks insight can offer

alan

after digging around in nlog source code figured out going on here.

the real problem was putting nlog.config file in wrong place , nlog not finding it. putting in add-in directory .addin file , binaries. rather throwing kind of exception nlog silently disabling logging. reasonable behavior in hindsight since it's legitimate logging disabled if config file not present. anyway, no logs getting written , first thought might permissions issue. tried create file (test.log) , write in add-in code , saw exception above reinforced (incorrect) suspicion there's security model prevents add-ins writing file system.

so, need mindful of directories:

  • the add-in directory: .addin file , related binaries live. visual studio add-ins , load them from.

  • the default directory visual studio: remember it's devenv.exe owns process, not add-in. default directory devenv.exe lives not add-in lives. note directory write protected non-admin users. nlog nlog.config file!

  • the path logfile target in nlog.config file: needs writeable location. specifying file (e.g. test.log) in target represent file in default working dir visual studio which, noted above, not writeable location.

so, in order make things work had to:

  • put nlog.config file in c:\program files (x86)\microsoft visual studio 11.0\common7\ide. needed admin.
  • specify full (writeable) path logfile in nlog.config

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -