ASPNET Event Log Access

From: Charles Leonard (elmsdn13_at_hotmail.com)
Date: 08/27/03


Date: Wed, 27 Aug 2003 08:14:17 -0700


>From what I have read, finding a convenient way to access
and write to the Application Event Log from within a Web
Service application is a common, frustrating problem. I'm
not quite sure why this was made so difficult for
something that seems so harmless, necessary and is the
common logging standard.

Here's what I have tried:

*Add the ASPNET user to the Application Event Log
security with "Full Control" in the Registry (using
regedt32).

The above suggestion works only if the Application Log
source (i.e. the name of the application) preexists in the
Registry. Below is an excerpt of the code I am using to
access/write to the Application Event Log within my Web
Service:

        objEventLog = new System.Diagnostics.EventLog();
        if (!System.Diagnostics.EventLog.SourceExists
(strProgName))
        
        System.Diagnostics.EventLog.CreateEventSource(
                        "MyProg", "Application");
        objEventLog.Source = strProgName;
objEventLog.WriteEntry(strData,
System.Diagnostics.EventLogEntryType.Error);

The above code works great in a non-web application. But,
it will not work within my Web Service unless the "MyProg"
source pre-exists in the Registry (along with the proper
ASPNET permissions established). Of course I can
accomplish the source creation by running the code outside
the Web Service in the non-web application to create my
log source.

However, this circumstance is not ideal when you consider
deployment into a production environment. That leaves two
things I can do in the installation process: 1) Run the
non-web application during the installation process to
create the log source 2) deliver registry settings to
create the log source within the Application Log.

My complaint is that this is a lot of trouble to do
something that seems innocuous. Logging to the
Application Event log is a very useful tool and something
administrators have come to expect from Windows programs.
Furthermore, since I have told the Registry that ASPNET
has "Full Control" (write access, etc.) one would think
that should be enough to let the above code work without
having to do anything extra (i.e. I should not have to
manually figure out how I can create a log source-the
above code should just work).

Does anyone know of any other tricks to allow the above
code to work within a Web Service that is simple and does
not involve impersonation? Also, does anyone know if
Microsoft has any plans to address this issue in a future
version of Visual Studio .NET?

Thanks.

--Charles Leonard



Relevant Pages

  • Re: Windows Explorer is CRASHING!!! (YET MORE info)
    ... >>I'm pretty sure the errors you're seeing in the event log are not related. ... >>> The local computer may not have the necessary registry information or message ... Server performance data will not be returned. ... >>> Error code returned is in data DWORD 0. ...
    (microsoft.public.win2000.general)
  • Re: Development of event log message file
    ... registry info is because the Application entry in the registry for the ... EventLog Service does not have a key for an EventMessageFile. ... The original reason for the post was to ask if there was a better way for ... To read the event log on a remote computer, which is what it sounds like you ...
    (microsoft.public.vsnet.general)
  • Re: security exception within Microsoft Application Block ExceptionManager.vb
    ... I am in the registry now. ... > ASPNET account doesn't have permission to create EventLog's, ... > Accessing the Event Log ... > not have sufficient permissions to create new event sources. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: No RPC Server service visibible services - endpoint mapper err
    ... There are no errors in the event log on the ... server relating to the RPC service. ... list of services nor can you find the registry key for it under ...
    (microsoft.public.windows.server.sbs)
  • Event ID: 1508
    ... After searching to my limited capacity I'm unable to assess what is causing ... an event log that is troubling me. ... Windows was unable to load the registry. ... I am logged in as a Domain Administrator and have every permission ...
    (microsoft.public.windowsxp.help_and_support)