Tar
Tar

Reputation: 9035

How to exclude from OnMethodBoundaryAspect-based logging?

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 ?

Upvotes: 3

Views: 872

Answers (1)

qujck
qujck

Reputation: 14578

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

Upvotes: 2

Related Questions