0

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

jww
  • 97,681
  • 90
  • 411
  • 885
user1523935
  • 87
  • 1
  • 1
  • 11

2 Answers2

0

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();
    }
}
StaWho
  • 2,488
  • 17
  • 24
0
void Main()
{
    var eventLog = new EventLog();
    eventLog.Log = "Security";
    
    eventLog.Entries.Cast<EventLogEntry>()
    .OrderByDescending(e => e.TimeGenerated);
}
  • 1
    This isn't exactly what the question is looking for. It asks for a way to get the "event instantly when it logs". – BDL Mar 27 '21 at 11:20