What do I need to change to allow my IIS7 ASP.Net 3.5 application to create an event source and log events to Windows EventLog?

ASP.Net 3.5 running under IIS 7 doesn’t seem to allow this out of the box.

        if (!EventLog.SourceExists("MyAppLog"))
            EventLog.CreateEventSource("MyAppLog", "Application");

        EventLog myLog = new EventLog();
        myLog.Source = "MyAppLog";
        myLog.WriteEntry("Message");

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I’ve copied this answer from here (the question was Log4Net but the answer still applies). The technet link misses a vital step.

Create a registry key

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetserviceseventlogApplicationMY-AWESOME-APP

Create a string value inside this

Name it EventMessageFile, set its value to

C:WindowsMicrosoft.NETFrameworkv2.0.50727EventLogMessages.dll

That path appears to work in both 64 bit and 32 bit environments.

With this technique you don’t need to set permissions in the registry, and once the key above is created it should just work.

Alternatively
If you don’t have a large server farm but just a small “web garden” you could run a console application on each server that creates the event log source using EventLog.CreateEventSource, make sure the console application is run by an administrator.

Method 2

This is part of windows security since windows 2003.

You need to create an entry in the registry under HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesEventlogApplication Make sure that network service or the account you impersonate has permission to this registry key.

@CheGueVerra’s link: Requested Registry Access Is Not Allowed

Method 3

Right click the application and choose “Run as Administrator”


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x