Enterprise Library 5.0异常处理程序:如何从错误消息中删除部分

时间:2012-04-17 20:46:03

标签: enterprise-library mongodb-.net-driver

我在我的网络应用程序中编写了一个带有Entlib 5.0的自定义MongoDB侦听器作为我的异常处理程序。它的效果很好,除了它为下面的每个“行”创建一个文档条目,包括空行:

----------------------------------------
Timestamp: 4/17/2012 4:13:50 PM
Message: HandlingInstanceID: c3c5f58a-89b3-4b64-b05d-3f72f998bab4
An exception of type 'System.NullReferenceException' occurred and was caught.
-----------------------------------------------------------------------------
04/17/2012 16:13:50
Type : System.NullReferenceException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Object reference not set to an instance of an object.
Source : MyCo.Webservices.TheCoolService
Data : System.Collections.ListDictionaryInternal
TargetSite : System.String TestExceptionHandling()
Stack Trace :    at Logging.TestExceptionHandling() in C:\tfs\Development\Source\MyCo.Webservices.TheCoolService\Logging\Logging.cs:line 55


----------------------------------------

我想做的是将大部分信息都放入一个文档中,以便针对同一错误没有10个不同的文档。即使编写我自己的Exception formattter(http://msdn.microsoft.com/en-us/library/ff664587(v=pandp.50).aspx),我仍然无法绕过对customlistener.Write()方法的多次调用,每个方法都会在我的mongodb集合中创建一个新文档。

我的Entlib体验有限,但除非我从头开始编写整个ExceptionFormatter,否则我看不到如何解决它。任何人都有任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

发现我的问题。事实证明我错过了我的侦听器上的TraceData()方法实现。一旦我告诉它该做什么,它就像单个WriteLine()调用一样处理错误消息。