Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"); 
like image 214
JTew Avatar asked Nov 13 '08 02:11

JTew


People also ask

How do I create an event source in Event Viewer?

To create an event source, you need to have a name for your new source (called the Event Source Name) and the name of the log where the event source will be a part. If the event log entries would be written to the standard “Application”, “System” or “Security” logs, then you can use that as the name of the log.

How do I add permissions to event logs?

Navigate to HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Services > EventLog > Security, right-click and select "Permissions..." Click "Add...", find the account running Secret Server, then click OK. Check Read in the Allow column, then click OK to apply the permission.

Which of the following methods can be used to delete an EventLog object?

You can use the static members of EventLog to delete logs, get log lists, create or delete a source, or determine if a computer already contains a particular source. There are three default event logs: Application, System, and Security.


2 Answers

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_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MY-AWESOME-APP

Create a string value inside this

Name it EventMessageFile, set its value to

C:\Windows\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.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.

like image 113
Chris S Avatar answered Sep 23 '22 02:09

Chris S


This is part of windows security since windows 2003.

You need to create an entry in the registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application 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

like image 31
Aaron Fischer Avatar answered Sep 25 '22 02:09

Aaron Fischer