如何跟踪每个调用的方法 [英] How to trace every method called
问题描述
我正在做一个现有的项目,我想找出所有来电,也许转储到一个日志文件。
I have an existing project where I would like to find out all calls being made and maybe dump into a log file.
我看的at这个线程,但没有太大的帮助。
我试过PostSharp,示例展示了如何实现它。但我需要一个属性添加到每一次缝补方法。作为一个已有的项目,在众多的方法,是不是一种可行的选择。
I had a look at this thread, but didnt help much. I tried PostSharp, and the example shows how to achieve it. But I need to add an attribute to every darn method. Being an existing project, with in-numerous methods that is not a feasible option.
有没有其他的方法,使我可以快速追踪的所有电话?
Is there any other means by which I can quickly trace all calls made?
推荐答案
PostSharp无疑提供了一种适用于多个目标的一个方面不与明确属性的装饰他们。请参见组播属性。
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.
}
,然后应用在覆盖你的使用情况(如一种方式方面。在AdventureWorks.BusinessLayer命名空间中所有公共成员):
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 )]
这篇关于如何跟踪每个调用的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!