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
|
Download the Full Working Version of this Project written with Visual Studio.NET VB.NET 2005 Here!
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!