title: Attempted to perform an unauthorized operation error while accessing event log
body: <p>I have a Windows Service in C# which creates an Event Log like so:</p>
  
  <pre><code>public partial class WizardService : ServiceBase
  {
      public WizardService()
      {
          InitializeComponent();
  
          // Setup logging
          if (!EventLog.SourceExists("WizardService"))
          {
              EventLog.CreateEventSource(
                  "WizardService", "WizardServiceLog");
          }
  
          eventLog1.Source = "WizardService";
          eventLog1.Log = "WizardServiceLog";
      }
  </code></pre>
  
  <p>The Windows Service can access this Event Log successfully.  The Windows Service is configured to run as Local Service.  This needs to work on Win7 and Windows Server 2008 R2.</p>
  
  <p>However, the Service also makes calls out to an ASMX Web Service.  I would like the ASMX Web Service to also be able to access the same Event Log but I get this error:</p>
  
  <pre><code>System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
    at Microsoft.Win32.RegistryKey.Win32ErrorStatic(Int32 errorCode, String str)
    at Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey, String machineName, RegistryView view)
    at System.Diagnostics.EventLogInternal.GetEventLogRegKey(String machine, Boolean writable)
    at System.Diagnostics.EventLogInternal.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
    at System.Diagnostics.EventLogInternal.SourceExists(String source, String machineName, Boolean wantToCreate)
    at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName)
    at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
    at System.Diagnostics.EventLog.WriteEntry(String message)
  </code></pre>
  
  <p>Here is the code that the ASMX Web Service uses:</p>
  
  <pre><code>public class WizardService : WebService
  {
      private EventLog eventLog;
  
      public WizardService()
      {
          eventLog = new EventLog("WizardServiceLog", "localhost", "WizardService");
      }
  
      private SomeOtherMethod()
      {
          eventLog.WriteEntry("Error : " + ex.Message + Environment.NewLine + ex.StackTrace);
      }
  }
  </code></pre>
  
  <p>The error occurs on the eventLog.WriteEntry() line.</p>