In SharePoint 2016, I got this error "The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security." when trying to write an event log to a custom source in Visual Web Part using C# to be shown in Event Viewer.
I know it's mainly a security and permission issue related to the current web application pool service account, therefore, In Regedit, I tried to set the Full control to the Application Pool account at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application with no avail.
I also tried to provide the full control permission to the Logs folder in Windows at this location C:\Windows\System32\winevt\Logs. But still, I can't write an event log entry to a custom source in Event Viewer.
Moreover, and besides the web application pool account, I granted the Network Service Account and IUSER the full control permission on the above locations (Registery, Logs folder).
Unfrothntly, still I can't check if the custom source exists or not to can write an entry with a custom source in Event Log Viewer using C# in SharePoint 2016 and I am still getting the same issue "The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security."
I am using the below C# code to check if the event viewer custom source or not in SharePoint Visual Web Part
How I can fix this security issue to can write an event log in Event Viewer in a specific custom source using C# in SharePoint Visual web part?