98

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?

Konrad Kokosa
  • 16,563
  • 2
  • 36
  • 58
user1480864
  • 1,455
  • 3
  • 16
  • 23
  • 1
    For what user you have given full access to `HKLM\SYSTEM\CurrentControlSet\services\eventlog`? – Konrad Kokosa Dec 05 '13 at 00:54
  • network service & IIS User – user1480864 Dec 05 '13 at 02:23
  • 1
    You will probably need to add it for your [application pool identity](http://www.iis.net/learn/manage/configuring-security/application-pool-identities) – Konrad Kokosa Dec 05 '13 at 07:55
  • Did my answer solve the problem or not? Please report if there's a different problem. – w128 Dec 06 '13 at 12:07
  • Check this **[The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.](https://debug.to/2683/source-found-but-some-all-event-logs-could-not-searched-inaccessible-logs-security)** – Mohamed Nov 19 '21 at 13:25

9 Answers9

88

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
Community
  • 1
  • 1
w128
  • 4,680
  • 7
  • 42
  • 65
  • 21
    If you're using a newer framework, the `EventMessageFile` value might be `C:\Windows\Microsoft.NET\Framework\v4.0.30319\EventLogMessages.dll` – mcolegro Jun 29 '15 at 21:49
  • I was looking for the registered name of my application, but the missing registry key is in fact "My App". – simaglei Oct 25 '16 at 12:09
  • 1
    Bottom line: it fails on `EventLog.CreateEventSource()` because of admin privileges being required to create the key. He either needs to run the app with said privileges (or Visual Studio, if debugging when running), or create the key ahead of time & check for it and not create it, if it's already there. – vapcguy Nov 07 '18 at 22:13
  • 3
    This is not a right solution, especially for end-user. – Yousha Aleayoub Dec 27 '19 at 12:44
  • You have to temporarily disable impersonate in the code, for more details Check this **[The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.](https://debug.to/2683/source-found-but-some-all-event-logs-could-not-searched-inaccessible-logs-security)** – Mohamed Nov 19 '21 at 13:26
52

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

Community
  • 1
  • 1
SharpC
  • 6,974
  • 4
  • 45
  • 40
13

I know, I am a little late to the party ... what happen a lot, you just use default settings in your app pool in IIS. In IIS Administration utility, go to app pools->select pool-->advanced settings->Process Model/Identity and select a user identity which has right permissions. By default it is set to ApplicationPoolIdentity. If you're developer, you most likely admin on your machine, so you can select your account to run app pool. On the deployment servers, let admins to deal with it.

T.S.
  • 18,195
  • 11
  • 58
  • 78
9

Whenever you start Visual Studio run it as administrator. It works for me.

SharpC
  • 6,974
  • 4
  • 45
  • 40
Divya
  • 373
  • 4
  • 3
6

try giving AppPool ID or Network Services whichever applicable access HKLM\SYSTEM\CurrentControlSet\services\eventlog\security also. I was getting the same error .. this worked for me. See the error is also saying that the inaccessible logs are Security Logs.

I also gave permission in eventlog\application .

I gave full access everywhere.

Aditi
  • 61
  • 1
  • 1
5

Locally I run visual studio with admin rights and the error was gone.

If you get this error in task scheduler you have to check the option run with high privileges.

SharpC
  • 6,974
  • 4
  • 45
  • 40
  • 3
    Who said "Visual studio"? You said! question has no mention of this – T.S. Dec 08 '17 at 17:26
  • 1
    If your deploying a service using Visual studio 2017 >> Developer Command Prompt for VS 2017 >> installutil.exe you get this error that exactly matches this pages title, hence it is a reasonably good place to put this answer (for Visual Studio users). When I ran the command prompt again as administrator it cure the error. – andrew pate May 13 '18 at 09:01
2

It could also be because, it might not be able to found the .dll file required. Either the file is not in the folder or is renamed. I faced the same issue and found that .dll file was missing in my bin folder some how.

2

Use NetworkService as Identity value in the application pool advanced settings when you are debugging in Visual Studio. ApplicationPoolIdentity is working if you open the site directly from the browser (or go to virtual directory in IIS and use Browse option at right).

Pablishe
  • 71
  • 1
  • 5
0

I recently started receiving this error inside of my internal NLog failures log, with Visual Studio 2013. The solution has been using NLog v2.0.0 for several years. Within the last month, our main log stopped working. To fix this I updated NLog to the newest version (v3.1.0) via Nuget. The security exception is now gone and ALL of the log messages are appearing again.

Additionally, I later found another Security exception and was able to fix it by following the instructions on this post in another thread.

Community
  • 1
  • 1
cat5dev
  • 1,317
  • 15
  • 12