Home All Groups Group Topic Archive Search About

Problems trying to write to Custom Eventlog

Author
15 Sep 2005 5:39 PM
moochin
I might be going out of my mind but I have been looking at this for
hours, and after a lot of smoking and banging my head I think I have
solved the problem, and thought someone might be interested.

I have an ASP.NET website which I needed to log errors to a custom log.
I create the custom log with the following code:

            AppEventLogInstaller = New EventLogInstaller
            ' Set the 'Source' of the event log, to be created.
            AppEventLogInstaller.Source = "App"
            ' Set the 'Log' that the source is created in.
            AppEventLogInstaller.Log = "TES"
            ' Add myEventLogInstaller to 'InstallerCollection'.
            Installers.Add(AppEventLogInstaller)

When trying to write to the event log
(Diagnostics.EventLog.WriteEntry("app", "test") I got the following
error:

Exception Details: System.Security.SecurityException: Requested
registry access is not allowed.

If I change the previous code to the following:

            AppEventLogInstaller = New EventLogInstaller
            ' Set the 'Source' of the event log, to be created.
            AppEventLogInstaller.Source = "App"
            ' Set the 'Log' that the source is created in.
            AppEventLogInstaller.Log = "ATES"
            ' Add myEventLogInstaller to 'InstallerCollection'.
            Installers.Add(AppEventLogInstaller)

Note the A in front of the TES, it works!!!!!

It seems that when it looks for the source it goes through the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\xxx keys
alphabetically looking for 'App' under each of the logs, unfortunately
it hits \security before \TES which has limited permissions and
therefore throws an error. I maybe wrong and I'm sure someone will tell
me if I am, but I'm tired and that is all I have to say.

Author
15 Sep 2005 7:15 PM
Nicole Calinoiu
This is due to a problem in the framework code that looks for the log in
which your event source is registered.  Even if you tell it which log to
use, this information is ignored, and it runs through the registry keys for
the logs in alphabetical order, attempting to find the log in which your
event source is registered.  When running under a non-admin user account, if
it hits the "Security" log before finding the event source, an exception
will be thrown due to insufficient user permissions on the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Security
registry key.  The only reasonable workaround in v. 1.x is to give your
custom log a name that precedes "Security" when sorted in ascending
alphabetical orders.  (This problem appears to be fixed in the v. 2.0
Framework.)



<mooc***@gmail.com> wrote in message
Show quoteHide quote
news:1126805943.306290.47960@z14g2000cwz.googlegroups.com...
>I might be going out of my mind but I have been looking at this for
> hours, and after a lot of smoking and banging my head I think I have
> solved the problem, and thought someone might be interested.
>
> I have an ASP.NET website which I needed to log errors to a custom log.
> I create the custom log with the following code:
>
>            AppEventLogInstaller = New EventLogInstaller
>            ' Set the 'Source' of the event log, to be created.
>            AppEventLogInstaller.Source = "App"
>            ' Set the 'Log' that the source is created in.
>            AppEventLogInstaller.Log = "TES"
>            ' Add myEventLogInstaller to 'InstallerCollection'.
>            Installers.Add(AppEventLogInstaller)
>
> When trying to write to the event log
> (Diagnostics.EventLog.WriteEntry("app", "test") I got the following
> error:
>
> Exception Details: System.Security.SecurityException: Requested
> registry access is not allowed.
>
> If I change the previous code to the following:
>
>            AppEventLogInstaller = New EventLogInstaller
>            ' Set the 'Source' of the event log, to be created.
>            AppEventLogInstaller.Source = "App"
>            ' Set the 'Log' that the source is created in.
>            AppEventLogInstaller.Log = "ATES"
>            ' Add myEventLogInstaller to 'InstallerCollection'.
>            Installers.Add(AppEventLogInstaller)
>
> Note the A in front of the TES, it works!!!!!
>
> It seems that when it looks for the source it goes through the
> HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\xxx keys
> alphabetically looking for 'App' under each of the logs, unfortunately
> it hits \security before \TES which has limited permissions and
> therefore throws an error. I maybe wrong and I'm sure someone will tell
> me if I am, but I'm tired and that is all I have to say.
>