我使用的VB.net代碼和SQL Server 2005如何存儲錯誤在SQL表或日誌文件如果在發送電子郵件
我havng下面的代碼在我的vb.net發送電子郵件錯誤碼。
Protected Sub ibtnSendInvites_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ibtnSendInvites.Click
Try
Dim emailList As New List(Of String)
For Each curRow As GridViewRow In GridView1.Rows
Dim chkSelect As CheckBox = CType(curRow.Cells(1).FindControl("chkSelect"), CheckBox)
Dim emailLabel As Label = CType(curRow.Cells(1).FindControl("lblEmailAddress"), Label)
If chkSelect.Checked Then
emailList.Add(emailLabel.Text)
End If
Next
For Each email As String In emailList
Dim SelectDelegateMessage As String = "Please confirm your booking for this course"
Dim SelectDelegateSubject As String = "User-Point Course Booking Invitation Email"
Dim SelectDelegateFrom As String = WebConfigurationManager.AppSettings("UserPointEmailFromAddress").ToString()
SendEmail.SendMessage(SelectDelegateSubject, SelectDelegateMessage, SelectDelegateFrom, email, "")
Next
GridView1.DataBind()
Catch ex As Exception
'Throw New Exception("Cannot Insert Duplicate Record", ex)
End Try
End Sub
現在我的問題是,有些時候,如果emailaddress無效或SMTP服務器響應我的應用程序得到掛起。我想將我的SMTP服務器生成的錯誤記錄在表或任何日誌文件中,如果我可以通過發送錯誤的詳細信息發回給管理員的電子郵件,那將會很好。
請建議!
謝謝。
最好的問候, MS
好點,記錄「所有」錯誤是一個好主意。然而,一旦您對此有點認真,您可能需要引入一些邏輯,以避免發送日誌過多,當然發送太多通知,以防出現突發錯誤。有一個名爲say「ErrorHandler()」的實用程序方法是一個好主意,其中所有日誌記錄(以及管理員通知等其他功能)都會發生。以這種方式,當關於錯誤處理的業務邏輯發生改變時,程序不會改變。 – mjv 2009-09-20 09:57:37
我會過濾出可能的404錯誤和ThreadAbortExceptions等錯誤。但是,我發現更多更多,值得記錄一切。我有一個網站每天要獲得超過10萬個請求,儘管由於網絡問題,我可能會有數千個錯誤發生,但記錄日誌證明在報告問題中是無價的。當它變得太大時,我經常截斷我的錯誤表。另外,我的通知系統不會通過電子郵件發送給我任何錯誤。當最近的Y分鐘出現> X錯誤時,我會收到通知。 – 2009-09-20 10:26:12