我的网络服务方法中有一个Try Catch,我在测试中输入的测试代码确实被点击并正确记录。我的catch中的日志记录代码被调试器命中,但没有记录,是否有原因?我认为它可能只是野兽的本质。可以这么说,它可能会在击中捕获时关闭页面的执行吗?
以下代码:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports log4net
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class LendingService
Inherits System.Web.Services.WebService
Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
<WebMethod()> _
Public Function ApplicantCreate() As String
Try
'This logs
log.Info("Testing Of LendingService")
'Throwing exception for testing purposes
Throw New NullReferenceException
Catch ex As Exception
'This does not log
log.Error("Error creating applicant: " & Server.GetLastError.Message)
'Eventually we will log errors here (same for all other methods below)
'Return "Test"
End Try
End Function
End Class
答案 0 :(得分:0)
我能够弄清楚问题是什么,以下一行引起了一些不稳定的行为:
log.Error("Error creating applicant: " & Server.GetLastError.Message)
一旦我将其更改为:
,我将进入错误处理的后端.net代码log.Error("Error creating applicant: " & ex.Message)
它工作正常,我现在看到错误的日志条目。