C# 如何挂起动态代理';什么是拦截器?

C# 如何挂起动态代理';什么是拦截器?,c#,interceptor,castle-dynamicproxy,proxy-classes,C#,Interceptor,Castle Dynamicproxy,Proxy Classes,对于我使用的服务,我有一个计时拦截器: class TimingInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { var watch = new Stopwatch(); watch.Start(); try { invocation.Proceed();

对于我使用的服务,我有一个计时拦截器:

class TimingInterceptor : IInterceptor
{
    public void Intercept(IInvocation invocation)
    {                  
        var watch = new Stopwatch();
        watch.Start();
        try
        {
            invocation.Proceed();
        }
        finally
        {
            watch.Stop();

            PosLogFactory.Default.Verbose(
                 "{0} ms spent on calling {1}"
               , watch.Elapsed.TotalMilliseconds
               , invocation.Method.Name
               );
        }
    }
我使用这个拦截器来获取关于服务调用持续时间的日志信息

我只想在从应用程序的某个部分调用服务时使用它。
当从特定类调用服务时,是否有挂起侦听器日志的选项

不,没有内置的方法来做这样的事情。

我不相信DynamicProxy有内置的方法来做这件事。你必须自己写在拦截器里。