WCF service attribute to log method calls and exceptions

前端 未结 2 1614
醉梦人生
醉梦人生 2020-11-30 03:31

I have a requirement to log each method call in a WCF service, and any exceptions thrown. This has led to a lot of redundant code, because each method needs to include boil

2条回答
  •  鱼传尺愫
    2020-11-30 04:13

    You can try Audit.NET library with its Audit.WCF extension. It can log the WCF service interaction and is compatible with async calls.

    All you need to do is decorate your WCF service class or methods with the AuditBehavior attribute:

    [AuditBehavior()]
    public class OrderService : IOrderService
    { ... }
    

    The WCF extension uses an IOperationInvoker implementing Invoke and InvokeBegin/InvokeEnd. You can check the code here.

提交回复
热议问题