简体   繁体   English

Wcf跟踪错误到Windows服务

[英]Wcf trace errors to windows service

I have a WCF service running on a windows service. 我有一个在Windows服务上运行的WCF服务。 I want that any exception raised in the wcf service will get to the windows service so I can write it to the event log. 我希望在wcf服务中引发的任何异常都将转到Windows服务,因此我可以将其写入事件日志。

I have already made an ErrorHandler class which implements IErrorHandler and IServiceBehavior. 我已经创建了一个实现IErrorHandler和IServiceBehavior的ErrorHandler类。 And an ErrorHandlerElement which implements BehaviorExtensionElement. 以及一个实现BehaviorExtensionElement的ErrorHandlerElement。

How do I add listeners to the service and receive it at the windows service? 如何向服务添加侦听器并在Windows服务中接收它?

Do you really need the exception to get to the Windows Service to log it? 您是否真的需要异常才能访问Windows服务进行记录? Typically you want to have the global error handler, IErrorHandler, in WCF handle the exception to avoid the host restarting. 通常,您希望WCF中的全局错误处理程序IErrorHandler处理异常以避免主机重新启动。

In the past, I've use the EnterpriseLibrary Exception Handling and Logging frameworks ( EntLib5 ) to capture and log the exceptions. 过去,我使用EnterpriseLibrary异常处理和日志记录框架( EntLib5 )来捕获和记录异常。 By using a Event Log Trace Listener (the default) you can log the exception in the IErrorHandler and the exception doesn't need to propagate outside of WCF. 通过使用事件日志跟踪侦听器(默认),您可以在IErrorHandler中记录异常,并且异常不需要在WCF之外传播。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM