I am getting the following exception. I have given full control to Asp.net account on Eventlogs in Registry edit.
[SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.]
System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate) +664 System.Diagnostics.EventLog.SourceExists(String source, String machineName, Boolean wantToCreate) +109 System.Diagnostics.EventLog.SourceExists(String source) +14 Microsoft.ApplicationBlocks.ExceptionManagement.DefaultPublisher.VerifyValidSource() +41
I guess this is due to some configuration issue on server?
Didnt work for me.
I created a new key and string value and managed to get it working
EventLog.SourceExists
enumerates through the subkeys ofHKLM\SYSTEM\CurrentControlSet\services\eventlog
to see if it contains a subkey with the specified name. If the user account under which the code is running does not have read access to a subkey that it attempts to access (in your case, theSecurity
subkey) before finding the target source, you will see an exception like the one you have described.The usual approach for handling such issues is to register event log sources at installation time (under an administrator account), then assume that they exist at runtime, allowing any resulting exception to be treated as unexpected if a target event log source does not actually exist at runtime.
For me this error was due to the command prompt, which was not running under administrator privileges. You need to right click on the command prompt and say "Run as administrator".
You need administrator role to install or uninstall a service.
For me just worked iisreset (run cmd as administrator -> iisreset). Maybe somebody could give it a try.
A new event source needs to have a unique name across all logs including Security (which needs admin privilege when it's being read).
So your app will need admin privilege to create a source. But that's probably an overkill.
I wrote this powershell script to create the event source at will. Save it as
*.ps1
and run it with any privilege and it will elevate itself.Launch Developer command line "As an Administrator". This account has full access to Security log