当我在本地机器上执行以下代码时,它工作正常:
string eventLogName = "Security";
string sourceName = "BTHUSB";
string machineName = "Venus";
EventLog eventLog;
eventLog = new EventLog();
eventLog.Log = eventLogName;
eventLog.Source = sourceName;
eventLog.MachineName = machineName;
foreach (EventLogEntry e in eventLog.Entries)
{
Console.WriteLine("Entry type :{0}",e.EntryType);
}
当我执行上面的代码时,它不执行它会给出一个错误:
试图执行未经授权的操作
如何解决?