Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
Tutorial RSS
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Charts
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(VB)
Retrieve error message from event log in ASP.NET2.0(VB)


ASP.NET Error Handling Tutorial

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

I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.

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

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!



 
  Developer Resources







Server Intellect Rocks