Search code examples
c#aoppostsharp

PostSharp cannot exclude aspect from TargetMembers


The project I'm working is using PostSharp v4.2 to apply aspects like logging. The aspects are applied to targets with multicasting in AssemblyInfo.cs and they work fine. The multicasting is defined like

[assembly: LoggingAspect.LogAspect(AttributeTargetTypes = "regex:Api.Controllers.Services.*|Api.Controllers.Bananas.*", 
AttributeTargetMembers = "regex:Get.*|Create.*|Edit.*|Delete.*"
AspectPriority = 1, AttributeExclude = false)]

Now I need to exclude 2 methods from being logged. So to exclude the methods I added:

[assembly: LoggingAspect.LogAspect(AttributeTargetMembers = "GetUtilityToken", AspectPriority = 2, AttributeExclude = true)]

I don't know why but the aspect still gets applied to the Methods (GetUtilityToken, GetDevUtility) even though I applied the excluding as noted in documentation .. I even tried targeting with regex or wild card like AttributeTargetMembers = "Get*" but the aspect still gets applied. I have looked at this question PostSharp - excluding a method using AttributeExclude doesn't work but I don't have a LINQ query in that method ..

I can't figure out what am I missing ... Can anyone point out what may be causing this behavior ? or point out how can I debug this ?


Solution

  • You should use AttributePriority instead of AspectPriority.