title: System.Security.SecurityException when writing to Event Log
body: <p>I’m working on trying to port an ASP.NET app from Server 2003 (and IIS6) to Server 2008 (IIS7). </p>
  
  <p>When I try and visit the page on the browser I get this:</p>
  
  <blockquote>
    <p>Server Error in ‘/’ Application.</p>
    
    <p>Security Exception</p>
    
    <p>Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file.</p>
    
    <p>Exception Details: System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security</p>
    
    <p>Source Error:</p>
    
    <p>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and the location of the exception can be identified using the exception stack trace below.</p>
    
    <p>Stack Trace:</p>
    
    <p>[SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.]</p>
    
    <p>System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly) +562
    System.Diagnostics.EventLog.SourceExists(String source, String machineName) +251</p>
    
    <p>[snip]</p>
  </blockquote>
  
  <p>These are the things I’ve done to try and solve it:</p>
  
  <ol>
  <li><p>Give “Everyone” full access permission to the key <code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Security</code>. This worked. But naturally I can’t do this in production. So I deleted the “Everyone” permission after running the app for a few minutes and the error re-appeared.</p></li>
  <li><p>I created the source in the Application log and the Security log (and I verified it exists via regedit) during installation with elevated permissions but the error remained.</p></li>
  <li><p>I gave the app a full trust level in the <code>web.config</code> file (and using <code>appcmd.exe</code>) but to no avail.</p></li>
  </ol>
  
  <p>Does anyone have an insight as to what could be done here?</p>
  
  <p>PS: This is a follow up to this <a href="https://stackoverflow.com/questions/1261919/problem-in-accessing-writing-to-eventlog/1261960#1261960">question</a>. I followed the given answers but to no avail (see #2 above).</p>