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

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?

This question is related to c# iis event-log iis-8

The answer is


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


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.


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.


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


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


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.


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.


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.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to iis

ASP.NET Core 1.0 on IIS error 502.5 CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default Publish to IIS, setting Environment Variable IIS Manager in Windows 10 The page cannot be displayed because an internal server error has occurred on server The service cannot accept control messages at this time NuGet: 'X' already has a dependency defined for 'Y' Changing project port number in Visual Studio 2013 System.Data.SqlClient.SqlException: Login failed for user "This operation requires IIS integrated pipeline mode."

Examples related to event-log

Write to Windows Application Event Log The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security The source was not found, but some or all event logs could not be searched Description for event id from source cannot be found System.Security.SecurityException when writing to Event Log How to create Windows EventLog source from command line?

Examples related to iis-8

IIS Config Error - This configuration section cannot be used at this path The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security HTTP Error 500.19 and error code : 0x80070021 IIS: Display all sites and bindings in PowerShell IIS_IUSRS and IUSR permissions in IIS8 Dots in URL causes 404 with ASP.NET mvc and IIS WCF on IIS8; *.svc handler mapping doesn't work ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8