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

后端 未结 4 1998
旧时难觅i
旧时难觅i 2021-01-03 21:31

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

if (!EventLog.SourceExists(\"SomeName\"))
EventLog.CreateEventSource(\         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 22:00

    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?.

提交回复
热议问题