When I run the code below I get Exception Unhandled System.Security.SecurityException:'Requested registry access is not allowed'. I have all the necessary machine access.
namespace EventViewer
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcom to Event Log Viewer");
Console.WriteLine("Please enter Retrieve to Retrieve EventLogs");
string Retrieve = Console.ReadLine();
string Logs = Retrieve;
switch (Logs)
{
case "Retrieve":
EventLog eventLog;
eventLog = new EventLog();
eventLog.Log = "Security";
eventLog.Source = "Security-Auditiing";
eventLog.MachineName = "Cheetah";
var count = 0;
foreach (EventLogEntry log in eventLog.Entries)
{
if (count > 200)
{
return;
}
Console.Write("eventLog.Log: ", eventLog.Log);
}
break;
}
}
}
}