Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security [duplicate]

I am getting error:

The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security

When I run below code to capture errors on Win 2K12 R2 server IIS 8.5

EventLog elog = new EventLog(); EventLog.CreateEventSource("MyApp", "Application"); EventLog.WriteEntry(Source, swError.ToString(), EventLogEntryType.Error); 

I've given full access to HKLM\SYSTEM\CurrentControlSet\services\eventlog but it is not working still. What shall I do to fix it?

like image 528
user1480864 Avatar asked Dec 05 '13 00:12

user1480864


People also ask

How do I give permission to an event log?

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.

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.

Where does EventLog WriteEntry write to?

The WriteEntry method writes the given string directly to the event log; it does not use a localizable message resource file. Use the WriteEvent method to write events using a localized message resource file.


2 Answers

See creating a registry key.

This problem can occur not only due to permissions, but also due to event source key missing because it wasn't registered successfully (you need admin privileges to do it - if you just open Visual Studio as usual and run the program normally it won't be enough). Make sure that your event source "MyApp" is actually registered, i.e. that it appears in the registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application.

From MSDN EventLog.CreateEventSource():

To create an event source in Windows Vista and later or Windows Server 2003, you must have administrative privileges.

So you must either run the event source registration code as an admin (also, check if the source already exists before - see the above MSDN example) or you can manually add the key to the registry:

  1. create a regkey HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MyApp;
  2. inside, create a string value EventMessageFile and set its value to e.g. C:\Windows\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll
like image 52
w128 Avatar answered Oct 07 '22 13:10

w128


I got this error when running Visual Studio. By running Visual Studio as Administrator the application was able to access the Security logs as it then had sufficient permissions (thus preventing the error).

like image 29
SharpC Avatar answered Oct 07 '22 14:10

SharpC