简体   繁体   English

使用 Castle 记录 WCF(和其他)中抛出的异常

[英]Using Castle for logging thrown exceptions in WCF (and otherwise)

I'm writing a WCF web service and I'm wondering if there's an elegant (aspect-oriented) way to use Castle interceptor mechanism for logging exceptions thrown by my web methods?我正在编写一个 WCF web 服务,我想知道是否有一种优雅(面向方面)的方式来使用 Castle 拦截器机制来记录我的 Z2567A5EC9705EB7AC2C984033E068 方法抛出的异常? I know about the IInterceptor inteface, but I could not find any exception information there.我知道IInterceptor接口,但在那里找不到任何异常信息。

I've seen Castle, AOP and Logging in .NET , but it only covers method's parameters.在 .NET 中看到了 Castle、AOP 和 Logging ,但它只涵盖了方法的参数。

Is there a better (WCF or Castle's) mechanism for doing this?是否有更好的(WCF 或 Castle 的)机制来执行此操作? BTW I'm using log4net for logging.顺便说一句,我正在使用 log4net 进行日志记录。

UPDATE: I know about WCF's logging facilities, but I was looking more for a general solution, not just in WCF environment.更新:我知道 WCF 的日志记录工具,但我更多的是寻找通用解决方案,而不仅仅是在 WCF 环境中。

Thanks in advance.提前致谢。

If you want to use Castle Interceptors in general, you could do something like this:如果您想在一般情况下使用 Castle Interceptors,您可以执行以下操作:

public void Intercept(IInvocation invocation)
{
   //do some preprocessing here if needed
   try
   {
      invocation.Proceed()
   }
   catch(Exception e)
   {
      LogException(e);
      throw;
   }
   finally
   {
      //do some postprocessing jf needed
   }
}

You should use the build in WCF tracing and logging.您应该使用 WCF 跟踪和日志记录中的构建。 Then you can use the WCF Trace Viewer which will piece together logs from service and client so that you can see the full message flow.然后,您可以使用 WCF 跟踪查看器,它将来自服务和客户端的日志拼凑在一起,以便您可以看到完整的消息流。

http://www.devx.com/dotnet/Article/37389/0/page/6 http://www.devx.com/dotnet/Article/37389/0/page/6

There is the IErrorHandler interface in WCF: WCF中有IErrorHandler接口:

public interface IErrorHandler
{
    bool HandleError(Exception error, MessageFault fault);
    void ProvideFault(Exception error, ref MessageFault fault, ref string faultAction);
}

More details here: http://www.extremeexperts.com/Net/Articles/ExceptionHandlingInWCF.aspx更多详细信息: http://www.extremeexperts.com/Net/Articles/ExceptionHandlingInWCF.aspx

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

相关问题 使用SignalR在多个项目之间进行日志记录-日志记录为空并且没有引发异常吗? - Using SignalR for logging across many projects - Logging is empty and no exceptions thrown? ChannelFactory引发的WCF异常 - WCF Exceptions thrown by ChannelFactory 使用城堡测井功能将Castle Windsor 4.0.0版和NLog结合起来 - Combining Castle Windsor version 4.0.0 and NLog using Castle Logging Facility 使用PerWcfSession生活方式与Castle WCF集成工具 - Using PerWcfSession lifestyle with Castle WCF Integration Facility 使用Castle Windsor使用工厂方法解决WCF服务 - Using Castle windsor to resolve WCF service usingfactorymethod 在后台线程中全局捕获WCF异步调用引发的异常 - Globally catch exceptions thrown from WCF async calls in a background thread 在处理已引发MessageSecurityException的WCF客户端时,Castle Windsor引发了CommunicationObjectFaultedException - Castle Windsor throws a CommunicationObjectFaultedException when disposing a WCF client that has thrown a MessageSecurityException 使用 Castle.Windsor 和 Polly 响应 429 异常(节流) - Responding to 429 exceptions (throttling) using Castle.Windsor and Polly 使用Common.Logging与Asp.net MVC和Castle Windsor - Using Common.Logging with Asp.net MVC and Castle Windsor 使用顶架和温莎城堡主持WCF服务 - Host WCF service using top shelf and windsor castle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM