Writing to Event Log in ASP.NET application

Writing to Event Log is not simple, but very simple:

// Create an EventLog instance and assign its source.

myLog = new EventLog();

= "MySource";


// Write an informational entry to the event log.   

to event log.");

EventLog is in System.Diagnostics namespase.

Before using the source of the EventLog, you have to create
it. But if you use the code like this:

//Create Event Log if It Doesn’t Exist

if (! EventLog.SourceExists("MySource"))


you will get the error:

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

Instead, go to registry editor (regedit), locate key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
and create a new key with the source name