简体   繁体   中英

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

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.

AFAIK, without AOP or directly logging code injections the only way is a profiling 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. However, you need to turn on Debug build flag, or supplying argument in 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

http://msdn.microsoft.com/en-us/library/gg512103(v=office.14).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM