[英]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.