Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Error Handling - Retrieve error message from event log in ASP.NET2.0(C#)
Retrieve error message from event log in ASP.NET2.0(C#)


ASP.NET Error Handling Tutorial

To retrieve error message or warning message from Windows event log in ASP.NET 2.0 and C# is very simple. This tutorial will show you how to get the error message from event log.

At first, import the namespace of System.Diagnostics

using System.Diagnostics;

Create Eventlog object

EventLog objEventLog = new EventLog("System");

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

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+"<br>");
}
}

Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.

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+"<br>");
}
}
}
}


Download the Full Working Version of this Project written with Visual Studio.NET C# 2005 Here!

Looking for the VB.NET 2005 Version? Click Here!


Looking for more ASP.NET Tutorials? Click Here!






 
  Developer Resources







Server Intellect Rocks