log4net writing to file. How to open up permissions

佐手、 提交于 2019-12-06 21:02:29

You should not be trying to write directly to the root folder. Under windows 7, you will either have to run as administrator or disable UAC for that to work and neither are recommended.

Instead you can write to a folder in the 'application data' area

If you are using a .config file to configure log, you can use something like

<file value="${ALLUSERSPROFILE}\CompanyName\ProductName\Log.txt" />

or

<file value="${APPDATA}\CompanyName\ProductName\Log.txt" />

depending on whether you want the log files to be specific to a user or not.

(Obviously you replace CompanyName and ProductName with your own details).

This should work on Xp/Vista/W7.

You have 3 options in my eyes:

  1. like mentioned always run your app as admin altough thats not a brilliant solution

  2. Use the local path of the executing app to store your log - I always prefer this method as I always know where my logs are ( AppDomain.CurrentDomain.BaseDirectory will help you)

  3. Use "My Documents" or some similar special folders - a quick google gives us: special folders

I hope this helps.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!