Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 460
Tar Avatar asked Feb 16 '26 00:02

Tar


1 Answers

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

like image 196
qujck Avatar answered Feb 18 '26 12:02

qujck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!