0

我需要Audit Failure在记录时立即访问Window log->Security 事件,有什么方法可以在记录时立即捕获它。我需要访问实时尝试。
目前我正在从EventLogEntryc# 中的类中阅读此内容,但我需要一个我的应用程序在Audit Failure发生时运行。

 foreach (EventLogEntry entry in log.Entries)
   {
     if (entry.EntryType==EventLogEntryType.FailureAudit)
       {
          ///
       }
   }

一些类似于:

    EventLog myNewLog = new EventLog();
    myNewLog.Log = "MyCustomLog";                      

    myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
    myNewLog.EnableRaisingEvents = true;

事件日志事件,有些像这样我也想触发 windows 日志

4

2 回答 2

0

您可以使用EventLog.GetEventLogs()方法获取 EventLogs:

class Program
{
    static void Main(string[] args)
    {
        EventLog log = EventLog.GetEventLogs().First(o => o.Log == "Security");
        log.EnableRaisingEvents = true;
        log.EntryWritten += (s, e) => { Console.WriteLine(e.Entry.EntryType); };
        Console.WriteLine(log.LogDisplayName);
        Console.ReadKey();
    }
}
于 2013-02-28T13:10:08.980 回答
0
void Main()
{
    var eventLog = new EventLog();
    eventLog.Log = "Security";
    
    eventLog.Entries.Cast<EventLogEntry>()
    .OrderByDescending(e => e.TimeGenerated);
}
于 2021-03-26T22:50:15.153 回答