How to trace every method called

前端 未结 3 1290
深忆病人
深忆病人 2020-12-29 03:46

I have an existing project where I would like to find out all calls being made and maybe dump into a log file.

I had a look at this thread, but didnt help much. I tr

3条回答
  •  感动是毒
    2020-12-29 04:11

    PostSharp certainly offers a way to apply an aspect to several targets without decorating them with attributes explicitly. See Multicast attributes.

    When developing (multicast) aspect you must specify its usage:

    [MulticastAttributeUsage(MulticastTargets.Method, TargetMemberAttributes = MulticastAttributes.Instance)]
    [AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true)]
    [Serializable]
    public class TraceAttribute : MethodInterceptionAspect
    {
    // Details skipped.
    }
    

    And then apply the aspect in a way that covers your use case (eg. all public members in AdventureWorks.BusinessLayer namespace):

    [assembly: Trace( AttributeTargetTypes="AdventureWorks.BusinessLayer.*", AttributeTargetMemberAttributes = MulticastAttributes.Public )]
    

提交回复
热议问题