I am trying to modify the sample trace app that ships with Postsharp so that the trace is applied to all classes in my namespace without explicitly putting the [QuickTrace] on top of each class. I have attached a screenshot. What am I doing wrong ? Right click open/view image for bigger picture. thank you
Asked
Active
Viewed 2,178 times
5
-
1Believe me, you don't want to do this.. – this. __curious_geek Aug 30 '11 at 14:53
-
When tracing a large app to understand what it is doing, it is better to first trace all and then selectively disable classes/methods that are not required as you start understanding. Just my opinion. thanks – Gullu Aug 30 '11 at 16:00
1 Answers
4
You're doing it incorrectly. You're trying to assign the aspects to the mscorelib which will wrap calls to any methods that reside in the mscorelib (not your current app) but you're negating that with the fact tyhat you're telling it to apply to methods only in the Trace namespace.
Just use
[assembly: QuickTrace()]
Done. On your aspect, add the following
[QuickTrace(AttributeExclude=True)]
[Serializable]
public QuickTrace : OnMethodBoundaryAspect
{
//..Aspect code here
}

Dustin Davis
- 14,482
- 13
- 63
- 119
-
Updated my answer. You need to exclude your aspect from being applied to your aspect. – Dustin Davis Aug 30 '11 at 16:12
-
Compiles now but there is no tracing lines printed to console. Almost like the whole solution/project is excluded. In program.cs above namespace Trace I have [assembly: QuickTrace(AttributeExclude = true)] thanks – Gullu Aug 30 '11 at 16:31
-
No, you add that to your ASPECT class. You're excluding it from everything now. – Dustin Davis Aug 30 '11 at 16:43
-
4You can't apply an aspect to itself, you would end up with stackoverflow (and then you would end up on stackoverflow asking why) – Dustin Davis Aug 30 '11 at 16:45
-
To apply solution wide, apply the assembly attribute in each project, or setup the build script to include the projects (advanced) or just use AttributeTargetAssemblies as you have been. You may need to get the latest CTP. Keep in mind that not all aspect types will work with the AttributeTargetAssemblies. You will need to add a declaration for each project (assembly) there is no way to do it for ALL assemblies. Also using AttributeTargetAssemblies only works for referenced assemblies. – Dustin Davis Aug 30 '11 at 17:11