开发者

where to write a log file?

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 endi开发者_开发技巧ng 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?


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)

where to write a log file?

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

See also:

  • Wrong path returned by Environment.GetFolderPath(Environment.SpecialFolder.ApplicationFolder) under IIS6 WebService
  • http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/890fa85a-b11a-4fbe-a333-cbe69abd72a7/
  • You can now load the user profile of the application pool identity

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜