<%@ Import Namespace="System.Diagnostics"%>
<%@ Import Namespace="System.Diagnostics"%> <script language="c#" runat="server" > void Entry2Log() { int [] array = new int[12] for( int intCounter=0; intCounter <= 12;intCounter++) { array[intCounter] = intCounter; Response.Write("The value of this counter is:" + intCounter + "<br />"); } } void Page_Error(object sender, EventsArgs e) { string errorMessage = "Error occurred" + Server.GetLastError(); Server.ClearError(); string LogName = "MyAppLog"; string SourceName = "MyAppSource"; if (!(EventLog.SourceExists(SourceName)); { EventLog.CreateEventSource(SourceName, LogName); } EventLog MyLog = new EventLog(); MyLog.Source = SourceName; MyLog.WriteEntry(errorMessage, EventLogEntryType.Error); } </script> <% Entry2Log %>
<%@ Import Namespace = "System.Web.Mail" %> <script language="c#" runat="server"> void sendMailTest() { int [] array = new int[12] for( int intCounter=0; intCounter <= 12;intCounter++) { array[intCounter] = intCounter; Response.Write("The value of this counter is:" + intCounter + "<br />"); } } void Page_Error(object sender, EventArgs e) string errorMessage = "Error occurred" + Server.GetLastError(); Server.ClearError(); MailMessage newMail = new MailMessage(); newMail.From = "x@y.com"; // whatever your address needs are newMail.To = "z@y.com"; // whatever your address needs are newMail.Subject = "This error has occurred" newMail.Body = errorMessage; SmtpMail.Send(newMail); } </script> <% sendMailTest(); %>
Build Your Own ASP.NET Website Using C# & VB.NET