我现在已经近一天地研究了这个问题,一次又一次,这是一个真正令人头疼的问题。发生异常时,我们的WCF服务不会记录足够的信息。事实上,当我调试它时,Visual Studio甚至不会打破错误,除非我勾选出“打破中断”的错误。调试选项,好像他们被别人抓到了,但我无法弄明白。
更奇怪的是,我现在已经知道,虽然这个问题困扰了我的本地主机和我们所有的部署环境,但同事的本地环境却没有这个问题。这是我在机器上抛出错误时看到的 - 请注意它没有可能有助于识别问题根源的堆栈跟踪或行号:
2016-12-13 22:53:27,093 [21] ERROR Redacted.WcfUtilities.ExceptionHandler - Exception caught at application level
System.NullReferenceException: test
at System.ServiceModel.Dispatcher.TaskMethodInvoker.InvokeEnd(Object instance, Object[]& outputs, IAsyncResult result)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeEnd(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage7(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage6(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
相比之下,我的同事在他的日志文件中获取了这些多汁的信息:
2016-12-13 22:51:33,340 [15] ERROR Redacted.WcfUtilities.ExceptionHandler - Exception caught at application level
System.NullReferenceException: test
at Redacted.AlsoRedacted.FurtherRedacted.<RedactedMethod>d__15.MoveNext() in C:\...filename.cs:line 169
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Further.UpThe.Stack.<RedactedMethod>d__143.MoveNext() in C:\...ADifferentFile.cs:line 625
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.ServiceModel.Dispatcher.TaskMethodInvoker.<InvokeAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.ServiceModel.Dispatcher.TaskMethodInvoker.InvokeEnd(Object instance, Object[]& outputs, IAsyncResult result)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeEnd(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage7(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
我知道,WcfUtilities.ExceptionHandler似乎是明显的罪魁祸首,但是我已经检查了它并且它非常无害,而且它在两种环境中都使用它而不会抑制其中一个中的日志信息。
有什么可以解释这种差异?是IIS,也许吧?我认为大多数设置都会在我们通过源代码控制共享的配置文件中定义。