I got this error The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security. when writing an entry to an event log in event viewer using C# in SharePoint solution visual web part deployed as a farm solution.
So I decided to ignore to check if the new custom source is already exist or not in event logs to avoid this error and tried to create it manually in Regedit at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application,
- I created a new Key as a custom source, then
- I created a new string with "EventMessageFile" as a name and "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\EventLogMessages.dll" as a value.
The new custom source is created successfully and no need now to check if this custom source already exists in the event log or not!
so I used the below C# code to write an event entry in the event log directly as below
EventLog.CreateEventSource("WPLogs", "MyLogs");
EventLog eventLog = new EventLog();
eventLog.Source = "WPLogs";
eventLog.WriteEntry("Error", EventLogEntryType.Error, 1001);
but I still get this error "Cannot open log for source "SourceName". You may not have write access".
My question is What're the required permissions to add an entry with a custom source in the event log using C# in the SharePoint solution?