Unauthorized Operation Error while logging to EventLog

Topics: Logging Application Block
Apr 5, 2009 at 3:34 AM

I have created a sample application using enterprise libarary logging application block
to log into event viewer. This application is hosted under IIS with anonymous user option checked on.
It logs into the event viewer perfectly.

I have another application which user forms authentication using enterprise libarary logging application block
to log into event viewer.Even this application is hosted under IIS with anonymous user option checked on.
This application uses WCF.

while logging i am not able to log the message in the event viewer.
I tried to debug the enterprise library source code and  found the error in this location

File name is :   ...\EntLibMay2007\App Blocks\Src\Logging\LogSource.cs

method name is :public void TraceData(TraceEventType eventType, int id, LogEntry logEntry, TraceListenerFilter traceListenerFilter)
  
line :   listener.TraceData(manager, Name, eventType, id, logEntry);

The stack trace information is given below.

"   at Microsoft.Win32.RegistryKey.Win32ErrorStatic(Int32 errorCode, String str)\r\n   at Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey, String machineName)\r\n   at System.Diagnostics.EventLog.GetEventLogRegKey(String machine, Boolean writable)\r\n   at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly)\r\n   at System.Diagnostics.EventLog.SourceExists(String source, String machineName)\r\n   at System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName)\r\n   at System.Diagnostics.EventLog.WriteEvent(EventInstance instance, Byte[] data, Object[] values)\r\n   at System.Diagnostics.EventLog.WriteEvent(EventInstance instance, Object[] values)\r\n   at System.Diagnostics.EventLogTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType severity, Int32 id, Object data)\r\n   at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedTraceListenerWrapperBase.TraceData(TraceEventCache eventCache, String source, TraceEventType severity, Int32 id, Object data) in C:\\EnterpriseLibaray\\EntLibMay2007\\App Blocks\\Src\\Logging\\TraceListeners\\FormattedTraceListenerWrapperBase.cs:line 83\r\n   at Microsoft.Practices.EnterpriseLibrary.Logging.LogSource.TraceData(TraceEventType eventType, Int32 id, LogEntry logEntry, TraceListenerFilter traceListenerFilter) in C:\\EnterpriseLibaray\\EntLibMay2007\\App Blocks\\Src\\Logging\\LogSource.cs:line 130"

error message : "Attempted to perform an unauthorized operation."

I have given full permissions to aspnet machine account in the registry entry at the below paths:

     HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog

     HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\Enterprise Library Logging

Is there any thing else i am missing .
I still wonder why my sample application is able to log and the second application is unable to log into event viewer.

Apr 5, 2009 at 5:31 PM

Another point i forgot to mention is that this machine in which the logging happens has both .Net 3.5 and 3.0 frameworks installed. The .Net 3.0 version has a CTP version of WCF. Will that be an issue here ??
Apr 7, 2009 at 11:24 AM
Edited Apr 7, 2009 at 11:25 AM
Hi,

Are you using Windows Server 2003? I found a post that discusses about setting permission to the Event log along with the steps that you've made. Please see this:  http://flimflan.com/blog/PermissionsOnTheWindows2003ServerEventLog.aspx

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com


Apr 8, 2009 at 6:15 AM

Hi Valiant,

Thank you for the reply.

We have this problem in both Windows Server 2003 and XP machines ( on the dev env ). The interesting part is that in some of the Dev XP machines logging is working fine
for the same application and in some other it is throwing the same error.

Let me go through your solution i will reply soon

Regards
Sajith