3

I have this logger:

[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); }
}

But there's an intensive function (many nested loops, performance-critical) that also bloats the log. How do I exclude it and all its subroutines ?

Tar
  • 8,529
  • 9
  • 56
  • 127

1 Answers1

2

You can do this with the AttributeExclude=true property of the aspect. The exclusion can be applied at the assembly level

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

or per method

[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() { ... }
  }
}

A more complete answer can be found here

qujck
  • 14,388
  • 4
  • 45
  • 74
  • 1
    It took me a while to consider it, since my question was "...How do I exclude it and all its subroutines ?", emphasizing the last part: "...and all its subroutines ?". But it seems that there's no pure `AOP` or `PostSharp` way to do it.. – Tar Mar 28 '13 at 07:30
  • 1
    There doesn't seem to be the automatic propagation you require. – qujck Mar 28 '13 at 10:03