views:

288

answers:

1

I have a ASMX web services running as 'network service'. I want to be able to write to a custom event log every time a web service is called (and when errors happen).

I have created a new event log (MyLog) using the following code running as admin on a Windows server 2008 machine:

                if (!EventLog.SourceExists(APPLICATIONNAME))
            {
                EventLog.CreateEventSource(APPLICATIONNAME, EVENTLOGNAME);
            }
            EventLog.WriteEntry(APPLICATIONNAME, "Service started", EventLogEntryType.Information);

where APPLICATIONAME is "MyApp" and EVENTLOGNAME is "MyLog" (names changed to protect the innocents).

Firstly, it creates a new "MyLog" event log (verified with eventvwr), but its contents are the same as the Application event log. I was expecting to get an empty, non-connected event log.

Secondly, when I try to write to the newly created event log from within the Application_Start method using the following code:

EventLog.WriteEntry(APPLICATIONNAME, "Service started", EventLogEntryType.Information);

I get a SecurityException of type System.Diagnostics.EventLogPermission.

I have tried to change the ACLs of the "MyLog" hive in the registry (as suggested on MSDN) but to no avail.

I'd rather not change the identity of the web service nor change the ACLs on the Application event log which is used by other applications on the system.

A: 

Since my web service is running in the context of SharePoint, I simply wrapped the call to EventLog.WriteEntry with SPSecurity.RunWithElevatedPrivileges.

Philipp Schmid