ASP.NET EventLog Access

Writing to the Event Log in ASP.NET is a piece of cake. The following is a static class that I have used time and time again to simply encapsulate the event logging writing code:

  1. span class=”st0″>"Application"

This class works great in a console application where you can run as administrator. However, when you try to run from an ASP.NET application for the first time on a new event source, most often you will get permission denied:

Requested Registry Access Is Not Allowed

For security purposes the ASP.NET application will run under a limited role (at least it should be). This limited role prevents the application from having permission to create a new event log source. The solution is simple… you can manually add in an event log source which will prevent the application from trying to create one (all apps can write a log, just not create an event source).

Here are some steps, however, be warned this is manually changing some registry settings – make sure you backup and complete at your own risk:

  1. Click Start, and then click Run.
  2. In the Open text box, type regedit.
  3. Locate the following registry subkey:
    HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesEventlogApplication
  4. Right-click the Application subkey, point to New, and then click Key.
  5. Type TEST for the key name.
  6. Close Registry Editor.

Check out some further MSDN notes and explanations here: http://support.microsoft.com/kb/329291