0

I am reading Windows Logs in C# through below code,

string log = "Application";
    EventLog demoLog = new EventLog(log);
    EventLogEntryCollection entries = demoLog.Entries;
    foreach (EventLogEntry entry in entries)
    {
        Console.WriteLine("Level: {0}", entry.EntryType);
        Console.WriteLine("Event id: {0}", entry.InstanceId);
        Console.WriteLine("Message: {0}", entry.Message);
        Console.WriteLine("Source: {0}", entry.Source);
        Console.WriteLine("Date: {0}", entry.TimeGenerated);
        Console.WriteLine("--------------------------------");
    }

enter image description here

Now, is there any way that whenever an event came up, the console give that output?

Here Console application should treat as "Subscription" application, which should give immediately the event output as soon as event generates.

Thanks!

user584018
  • 10,186
  • 15
  • 74
  • 160

2 Answers2

0

You can try to read periodically the logs and sort them by Date desc.

pushStack
  • 3,315
  • 1
  • 15
  • 14
0

I think, you can try with threading

using System.Threading