Firing an event everytime a new method is called

喜夏-厌秋 提交于 2019-12-05 23:40:53

问题


I am making a logger for a c# application which needs to log the time when each method was called each method's execution time.

I can do this by calling my own EventLogger.LogMethodCall method at the start of every method, but I was wondering if there was a way to make the CLR fire an event every time a new method is called so I wouldn't have to manually call my method.

Thanks.


回答1:


Try to look into PostSharp and Aspect Oriented Programming




回答2:


Perhaps you should use a profiler to get the information you need?




回答3:


I don't believe that can be done. Rather than write your own logger, may I recommend Log4Net?



来源:https://stackoverflow.com/questions/5764187/firing-an-event-everytime-a-new-method-is-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!