I'm using nlog to write log files for debugging purposes. Currently the log file location is set to:
<target
name="file"
xsi:type="File"
fileName="${specialfolder:folder=LocalApplicationData}/x/y.log"
but this is resulting in a the file being written to c:\x\y.log
, not %windir%\ServiceProfiles\NetworkService\AppData\Local\x\y.log
, as I would expect with asp.net/IIS running under NETWORK SERVICE
account.
Checking the value for Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
from the web application yields an empty/null string, which at least explains why my logs are ending up in the root.
So really two questions:
We have services written and running under NETWORK SERVICE
account that resolve this path correctly. What's special about asp.net/IIS such that no value is returned for this special folder?
Where is a safe and sensible place to write a log to, given that my asp.net process is running under NETWORK SERVICE
account?