Hi,
1. EnableRaisingEvents - this is used if you are writing a event log listener
- you usually provide a callback in your application that gets called when
a new event entry is written - this is NOT needed to write to the event log
2. The ASP.NET worker process does not have the privileges to create a brand
new event source - that's where the access denied is coming from
You have to pre-create the event source and log in, e.g. a console application
that is run with admin privileges. Afterwards you can write to the EventLog
with a least privilege account.
---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com
> Hi all,
>
> We want to be able to log to the event log when an error occurs in our
> web parts. Currently we cannot do that under SharePoint because it
> throws an exception.
>
> Below is the code where is fails:
>
> EventLog log = new EventLog("Application", ".", "MyThing");
> log.EnableRaisingEvents = true;
> On the second line it throws the following exception:
>
> - $exception {"Cannot open log Application on machine .. Windows has
> not provided an error code."} System.Exception
> {System.InvalidOperationException}
>
> The exception contains an inner exception stating "Access denied."
>
> Running the same code under an ASP.NET 2.0 application with an
> anonimus user access it works fine.
>
> Here are some facts:
> - We are using windows authendication in the WSS server
> - The users accessing the sharepoint site have domain accounts
> - If I access the SharePoint site with a user that is NOT
> administrator then
> it fails.
> - For Admins it works fine.
> - The Event log source gets installed by our installer to avoid other
> sequrity problems.
> How can I avoid the exception without having to make all users admins?
> Please help!!!
>
> Thanks in advance,
> Greg.