Solution: web application can not access event log

From: chuck rudolph (chuckrudolph_at_discussions.microsoft.com)
Date: 04/06/05


Date: Tue, 5 Apr 2005 16:51:02 -0700

Nicole and Joseph put me on the correct track. Here's the scoop. I wrote a
windows app (just because I had one laying around) that did a
EventLog.CreateEventSource("sourceName","logName") for a couple sources for a
"custom log". Then in my web application I did a EventLog el = new
EventLog("logName", ".", "sourceName") and then el.WriteEntry("stuff to log")
and the custom log was written without issue with the web application running
as the standard anonymous user.

So the key seems to be to do not attempt to create a eventLog or an
eventSource in a web application and you will be okay. Joseph is still
educating me on the permissions, so check the long thread if you want those
details....Chuck

"chuck rudolph" wrote:

> In the page_load, I have the following code:
> PermissionSet ps = new PermissionSet(PermissionState.None);
> ps.AddPermission(new EventLogPermission
> EventLogPermissionAccess.Instrument,"."));
> ps.Demand();
> EventLogPermission ps2 = (EventLogPermission)
> ps.GetPermission(typeof(EventLogPermission));
>
> foreach (EventLogPermissionEntry psx in ps2.PermissionEntries)
> {
> this.Response.Write("<p> Machine: " +
> psx.MachineName + " Bits: " + psx.PermissionAccess + " </p>");
> }
>
> When executed it writes:
> Machine: . Bits: Instrument
>
> Which would lead me to believe that I can write to an event log. But when I
> then try to execute these two lines of code:
>
> EventLog el = new EventLog("My Log",".","Login Category");
> el.WriteEntry("Login is getting ready to run!");
>
> ASP.Net (Microsoft .NET Framework Version:1.1.4322.2032) throws the
> following exception:
> Exception Details: System.Security.SecurityException: Requested registry
> access is not allowed.
>
> Any ideas?
>
>
>



Relevant Pages

  • RE: EventLog Source still created after deleting all references to it
    ... I have deleted all references that I could find related to the source ... application log and not my custom log. ... > I created the EventLog using the component on VS 2003 toolbar ... > Added an installer for it. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Windows Service AutoStart Problem (C#)
    ... I used a custom log in the eventlog and the ... > needed" radio button is selected; this radio button is located in the Log ... > Jeffrey Tan ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: EventLog woes
    ... MH> I can't for the life of me get an EventLog to log to a custom log. ... MH> Is there some special super-secret trick to getting event logging ...
    (microsoft.public.dotnet.languages.csharp)