How to audit failure events for Windows security eventlog in C#

不打扰是莪最后的温柔 提交于 2019-12-08 13:43:33

问题


i need to access Audit Failure under Window log -> Security event instantly when it logs, is there any way to capture it instantly when it logs. i need to access real time attempts.
currently i am reading this from EventLogEntry class in c#, but i need a my application to run when Audit Failure occurs.

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

some thing similar to:

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

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

Event log events, some like this i want to trigger windows log also


回答1:


You can get EventLogs using EventLog.GetEventLogs() method:

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();
    }
}


来源:https://stackoverflow.com/questions/15135717/how-to-audit-failure-events-for-windows-security-eventlog-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!