每次调用新方法时触发事件 [英] Firing an event everytime a new method is called
本文介绍了每次调用新方法时触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为 c#应用程序制作一个 logger ,该应用程序需要记录每种方法被称为每种方法的执行时间。
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.
我可以通过在每个方法的开头调用我自己的 EventLogger.LogMethodCall
方法来做到这一点,但是我想知道是否有一种方法可以使 CLR 会在每次调用新方法时触发一个事件,因此我不必手动调用我的方法。
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.
谢谢。
推荐答案
尝试查看 PostSharp 和面向方面的编程
Try to look into PostSharp and Aspect Oriented Programming
这篇关于每次调用新方法时触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文