Error When ASP.NET attempts to write to EventLog

Problem

I received the following error message while attempting to log an entry in the event log using System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type)

System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.

This would only occur when running my ASP.NET web application under Windows XP Professional. It does not occur when I push the site to production Windows 2003 web server.

Solution

After searching Google, I found this forum thread, which lead me to this KB article.

The solution that worked for me was under the "First Approach" heading. Here it is verbatim:

Create an event source under the Application event log in Registry Editor. To do this, follow these steps:

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

Note: "TEST" should be replaced by whatever text you set the EventLog Source property to.

Update (05/02/07): I used this same fix when I get the error message "Registry access is not allowed".

Published Wednesday, January 31, 2007 1:02 PM by Tod Birdsall
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

anonymous said:

>>>Note: "TEST" should be replaced by whatever text you set the EventLog Source property to.

What source property?  If you're in Enterprise manager, under what in what tree?  There are many "sources" in the tool.

March 24, 2008 7:12 PM
 

hudy said:

Hi, this is sollusion

void Application_Error(object sender, EventArgs e)

   {

       string message = this.Context.Error.Message;

       //Nastavenie permission pre zapis do Event logu.

       WindowsImpersonationContext wic = WindowsIdentity.Impersonate(IntPtr.Zero);

       string source = "SkReality";

       EventLog.WriteEntry(

           source,

           message,

           EventLogEntryType.Error);

       wic.Undo();

   }

Hudy

April 1, 2008 1:21 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit