At first, import the namespace of System.Diagnostics
using System.Diagnostics; |
Create Eventlog object
EventLog objEventLog = new EventLog("System"); |
Use looping to retrieve all error message from event log
If you want get the information or warning messages from event log, just use EventLogEntryType.Information or EventLogEntryType.Warning to replace EventLogEntryType.Error
foreach (EventLogEntry objEntry in objEventLog.Entries) { if(objEntry.EntryType==EventLogEntryType.Error) }{ Response.Write(objEntry.TimeGenerated+"-"+objEntry.Source+"- "+objEntry.Message+" }"); |
The flow for the code behind page is as follows.
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; using System.Diagnostics; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) }{ EventLog objEventLog = new EventLog("System"); }foreach (EventLogEntry objEntry in objEventLog.Entries) { if(objEntry.EntryType==EventLogEntryType.Error) }{ Response.Write(objEntry.TimeGenerated+"-"+objEntry.Source+"- "+objEntry.Message+" }"); |