We have some logging code (.NET 4.5) that needs to log to the event log for debugging/auditing purposes. The following code blows up with a SecurityException on Windows Server 2012.
private void RegisterSource(string source, string logName)
{
if (EventLog.SourceExists(source))
{
EventLog.DeleteEventSource(source); //We die here
}
EventLog.CreateEventSource(source, logName);
}
SecurityException:
{"Requested registry access is not allowed."}
Note, I am a local admin on this box so not sure why this code is failing. Please advise.