Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 13th, 2004, 01:12 PM
ricksterval's Avatar
ricksterval ricksterval is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 31 ricksterval User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Complete example using custom errors and write errors to the Event log

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Diagnostics" %>
<script language="VB" runat=server>

Public Sub Application_OnError(Sender as Object, E as EventArgs)
'Captures the error and converts to a string
dim LastError as Exception = Server.GetLastError()
Dim ErrMessage as String = LastError.toString()

Dim LogName As String = "MyLog"
Dim Message As String = "Url " & Request.Path & " Error: " & ErrMessage

' Create Event Log if It Doesn't Exist
If (Not EventLog.SourceExists(LogName)) Then
EventLog.CreateEventSource(LogName, LogName)
End if

Dim Log as New EventLog
Log.Source = LogName

'These are the five options that will display a different icon.
'The numbers are just to show the order. These aren't required
Log.WriteEntry(Message, EventLogEntryType.Information, 1)
' Log.WriteEntry(Message, EventLogEntryType.Error, 2)
' Log.WriteEntry(Message, EventLogEntryType.Warning, 3)
' Log.WriteEntry(Message, EventLogEntryType.SuccessAudit, 4)
' Log.WriteEntry(Message, EventLogEntryType.FailureAudit, 5)
End Sub
</script>



[bold]Default.aspx page[/bold]

<% @Language="VB" %>
<script language="VB" runat=server>
Sub Page_Load(Sender As Object, E As EventArgs)
If IsPostBack Then
'Declare all variables
dim x as integer
dim y as integer
dim z as integer

'set x and y to values to be divided by zero
x = 1
y = 0

'perform the division by zero to raise the error
z = x/y
End Sub
</script>

<html>
<head>
</head>
<body>
<form method="post" action="eventlog.aspx" name="form1" id="number">

<asp:Button id="abutton" type="submit" text="Click Me to generate an error" runat="server" />
</form>
</body>
</html>



[bold]Customerrorpage.aspx[/bold]

<html>
<head></head>
<body>
<h1>custom error page</h1>
</body>
</html>



[bold]404page.aspx --Capture all 404(Not Found pages)[/bold]

<html>
<head></head>
<body>
<h1>404 error page</h1>
</body>
</html>



[bold]403page.aspx --Capture all 403(Restricted pages)[/bold]

<html>
<head></head>
<body>
<h1>403 error page</h1>
</body>
</html>


Read Complete Article

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Complete example using custom errors and write errors to the Event log


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT