System.Diagnostics.Trace not working in web app under ApplicationPoolIdentity

冷暖自知 提交于 2019-12-03 09:31:21

What evidence do you have that your TraceListeners weren't being hit? Seems more likely to me that they were being hit, but they didn't have permission to access some required resource (such as a file). In which case the solution might be as simple as giving your ApplicationPoolIdentity permissions on the appropriate disk folder.

I suggest you post more details of the listeners you're using (e.g. the <system.diagnostics> section of your web.config file, and of the exact errors you're seeing.

I suspect it has something to do with the security permission needed to run unmanaged code.

Which of your trace listeners do you think uses unmanaged code?

We tried EventLogTraceListener and even TextWriterListener on a folder that the user should have permissions.

You need to explicitly give permissions to the application pool identity, which won't have permissions by default.

Give read/write permission to the folder used by TextWriterListener to "IIS AppPool\DefaultAppPool" or whatever application pool name you're using.

As for the event log, non-administrators don't typically have permission to create an Event Source, so you should either create the Event Source manually during application installation, or alternatively it might be possible to use an existing Event Source (such as ".NET Runtime").

I think that it's not a specific listener that needs unmanaged code permissions, but the whole tracing functionality.

You're barking up the wrong tree here. Permission to run unmanaged code is a Code Access Security permission, which wouldn't be affected by the account the application runs under. And you say it works fine under the LocalSystem account.

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