Created
March 24, 2010 01:29
-
-
Save rtipton/341885 to your computer and use it in GitHub Desktop.
C# -- Read From Event Logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you dont use sb variable, right?