此外,我有时将以下代码放在 Global 文件的 Application_Error 事件中以记录异常:
' Fires when an error occurs
' Code that runs when an unhandled error occurs
Dim ErrorDescription As String = Server.GetLastError.ToString
' Log the Error to Event Log
'Creation of event log if it does not exist
Dim EventLogName As String
EventLogName = ConfigurationManager.AppSettings("ApplicationLog").ToString()
If (Not EventLog.SourceExists(EventLogName)) Then
EventLog.CreateEventSource(EventLogName, EventLogName)
End If
' Inserting into event log
Dim Log As New EventLog()
Log.Source = EventLogName
Log.WriteEntry(ErrorDescription, EventLogEntryType.Error)
1 回答
我知道这是非常基本的,但你试过吗?这包含在 Web.config 文件中。
此外,我有时将以下代码放在 Global 文件的 Application_Error 事件中以记录异常: