Pregunta

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?

¿Fue útil?

Solución

If my knowledge is correct, the problem is that IIS doesn't load the profile for the user Network Service.

You could adjust this setting in the properties of the application pool (source)

load the user profile of the application pool identity

If you set this parameter to true, the call to Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) should return a correct result.

See also:

If it does not work, I would recommend to create a folder with the appropriate rights for the service account for logging purposes.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top