using AppData location in NLog

怎甘沉沦 提交于 2019-11-28 07:56:39
Oren Mazor

You're looking for the NLog special folders.

Example:

...fileName="${specialfolder:folder=ApplicationData}/Program/file.txt"...
bkaid

Oren's answer should be the right answer. However, for the life of me I couldn't get it to work with my .NET 4.0 website using nLog 2.0.0.0. I ended up using simply

fileName="${basedir}app_data\logs\${shortdate}.log" 

${specialfolder:ApplicationData} also works

The previous answers helped solve the problem I was having, but a couple of years later and the solution is now somewhat different under v4.3. The directory and filename are combined with the path.

@theGecko's link is still current for the syntax, but the page is deficient of an example:

https://github.com/nlog/NLog/wiki/Special-Folder-Layout-Renderer

The following example would write the file myLog.log to the current users application data roaming directory C:\USers\current.user\AppData\Roaming\My\Path\Somewhere:

fileName="${specialfolder:dir=My/Path/Somewhere/:file=myFile.log:folder=ApplicationData}"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!