Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
Retrieve error message from event log in ASP.NET2.0(VB) (0 Comments)
Admin: Posted Date: April 4, 2010

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.

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

Dim objEventLog As EventLog = New EventLog("System")

We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.

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

 

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: