Monday, March 9, 2009

Error writing to the Event Log - Windows Server 2008

The EventLog.WriteEntry code runs successfully under Win Server 2003, but doesn't execute with Windows Server 2008. This line generates and error:

"The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security".

This can be resolved by following the below steps:

#1 Go to Start -> Run -> regedit

#2 Navigate to Computer > HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog

#3 Right click on "EventLog" key, select Permissions, and add the [Network Service] account with read/write permissions.

Note: Microsoft seems to have replaced the ASPNET account with the "Network Service" account.

#4 Restart the IIS (start -> Run -> iisreset)

#5 Now Go to Start -> Administrative Tools -> Computer Management -> Local Users and Groups -> Groups

Double click the [Administrator] Group -> Add the "Network Service" account.

Go back and try to refresh your web page again.

There you Go.....

Hope this saves some time for the others.