неделя, 25 септември 2011 г.

"Access Denied" error when writing into Event Log

When EventLog.WriteEntry(...) is used to write a log record in specific event log a pretty common error is the "Access Denied" message. That means you need to grant access to the user account that's been used by your Application pool. The account your web application uses to run is in "Internet Information Services (IIS) Manager -> Application Pools -> Your web Application Pool -> Advanced Settings -> Identity".
You need to give this user Read/Write permissions in the Log that you are trying to write into.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\YourLogName
It's accessible by the Register Editor.
The usual accounts that ASP.NET uses are NETWORK SERVICE (in WinSrv2003/2008 and Win7,Vista) and ASPNET in WinXP.