DotNet Tutorials

Server Intellect

 Retrieve error message from event log in ASP.NET2.0(VB)

To retrieve error message, information and warning message from Windows event log in ASP.NET 2.0 and VB.NET 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

Imports System.Diagnostics;

Create Eventlog object

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

Dim objEventLog As EventLog = 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

For Each objEntry In objEventLog.Entries
If objEntry.EntryType = EventLogEntryType.Error Then
Response.Write(objEntry.TimeGenerated & "-" & objEntry.Source & "-" & objEntry.Message & "<br>")
End If
Next

The flow for the code behind page is as follows.

Imports System.Diagnostics
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objEventLog As EventLog = New EventLog("System")
Dim objEntry As EventLogEntry

For Each objEntry In objEventLog.Entries
If objEntry.EntryType = EventLogEntryType.Error Then
Response.Write(objEntry.TimeGenerated & "-" & objEntry.Source & "-" & objEntry.Message & "<br>")
End If
Next

End Sub
End Class

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.





Looking for the C#.NET 2005 Version? Click Here!


Looking for more ASP.NET Tutorials? Click Here!
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect