Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem when trying to use EventLog.SourceExists method in .NET

Tags:

c#

.net

I am trying to use eventlogs in my application using C#, so I added the following code

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

The EventLog.SourceExists causes SecurityException that says
"The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security."

I am running as administrator in Windows 7.

Any help would be appriciated.

like image 368
user850010 Avatar asked Jul 18 '11 16:07

user850010


1 Answers

This is a permissions problem - you should give the running user permission to read the following registry key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog 

Alternaitvely you can bypas the CreateEventSource removing the need to access this registry key.

Both solutions are explained in more detail in the following thread - How do I create an Event Log source under Vista?.

like image 69
Justin Avatar answered Sep 21 '22 15:09

Justin