Skip to content

Instantly share code, notes, and snippets.

@rtipton
Created March 24, 2010 01:29
Show Gist options
  • Save rtipton/341885 to your computer and use it in GitHub Desktop.
Save rtipton/341885 to your computer and use it in GitHub Desktop.
C# -- Read From Event Logs
using System;
using System.Text;
class Program
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
System.Diagnostics.EventLog log = new
System.Diagnostics.EventLog("Application");
DateTime dt = DateTime.Now.AddHours(-5.00);
Console.WriteLine(dt.ToString());
foreach (System.Diagnostics.EventLogEntry entry in log.Entries)
{
if (entry.TimeGenerated > dt)
//if (entry.Source.Equals("Application Hang") && (entry.TimeGenerated > dt))
//if (entry.Source.Equals(".NET Runtime 2.0 Error Reporting") && (entry.TimeGenerated > dt))
{
Console.WriteLine(entry.Source);
Console.WriteLine(entry.EntryType);
Console.WriteLine(entry.Message);
Console.WriteLine("--------");
}
}
Console.WriteLine("Done");
Console.ReadLine();
}
}
@pizzoleto
Copy link

you dont use sb variable, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment