3

我有这个记录器:

[Serializable]
[AttributeUsage(AttributeTargets.All)]
public class MethodsInterceptAspect : OnMethodBoundaryAspect {
    public override void OnEntry(MethodExecutionArgs args) { Logger.LogMethodEntry(args.Method, DateTime.Now); }
    public override void OnExit(MethodExecutionArgs args) { Logger.LogMethodExit(args.Method, DateTime.Now); }
}

但是有一个密集的函数(许多嵌套循环,对性能至关重要)也会使日志膨胀。如何排除它及其所有子程序?

4

1 回答 1

2

您可以使用AttributeExclude=true方面的属性来执行此操作。排除可以在装配级别应用

[assembly: Trace("Business", AttributeTargetTypes="BusinessLayer.*", AttributePriority = 1)]
[assembly: Trace(AttributeTargetMembers="Dispose", AttributeExclude = true, AttributePriority = 2)]

或按方法

[assembly: Trace("Business", AttributeTargetTypes="BusinessLayer.*")]
namespace BusinessLayer
{
  public class Process : IDisposable
  {
   public Customer Create(string value) { ... }
   public void Delete(long id) { ... }

   [Trace(AttributeExclude=true)]
   public void Dispose() { ... }
  }
}

可以在这里找到更完整的答案

于 2013-03-21T09:53:03.620 回答