[英]How to know when a method in a class is being executed
I'm trying to write a log to monitor the execution time of a method for our application. 我正在尝试编写日志以监视应用程序方法的执行时间。 Is it possible to know when a method in a class is being executed without using Aspect-oriented programming.
是否可以知道何时在不使用面向方面的编程的情况下执行类中的方法。
I don't want to go into every method to write a log there so I hope someone faced this issue and can give me some suggestion. 我不想进入那里写日志的所有方法,所以我希望有人遇到这个问题并能给我一些建议。
Updated: I'm writing a SharePoint application using .Net 3.5 更新:我正在使用.Net 3.5编写SharePoint应用程序
Try using breakpoints. 尝试使用断点。 Press F10 on the space at the left side of the method, and from there, the debugging starts, where you'd be able to see value and property change after its execution.
在方法左侧的空白处按F10键,然后从那里开始调试,在调试之后,您可以在其中看到值和属性的变化。
AFAIK, without AOP or directly logging code injections the only way is a profiling API . AFAIK,没有AOP或直接记录代码注入,唯一的方法是配置API 。
I wouldn't choose that way for one-time task, it isn't easy. 对于一次性任务,我不会选择这种方式,这并不容易。
Addtional to @Dennis answer, I think System.Diagnostic.Debug is a choice to know when your method is executed beside Aspect-oriented programing. 除了@Dennis答案,我认为System.Diagnostic.Debug是了解何时在面向方面的编程旁边执行您的方法的选择。 However, you need to turn on Debug build flag, or supplying argument in csc.exe
但是,您需要打开Debug build标志,或在csc.exe中提供参数。
/define:DEBUG
in sp 2010 you can turn on developer dashboard (on dev stage only for safety) this will give you abreakdown of calls and times 在sp 2010中,您可以打开开发人员仪表板(仅出于安全起见仅在开发阶段),这将使您可以减少通话次数和时间
http://msdn.microsoft.com/en-us/library/gg512103(v=office.14).aspx http://msdn.microsoft.com/en-us/library/gg512103(v=office.14).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.