C# Ottenere nome della classe e del metodo chiamante

Mi serviva per realizzare un log, ho trovato spunto qui: www.coding4art.com (tra l’altro un blog fatto molto bene):

string classe = (new StackTrace()).GetFrame(1).GetMethod().DeclaringType.Name
string metodo =  (new StackTrace()).GetFrame(1).GetMethod().Name;

Qualche informazione sullo StackTrace la trovate qua:

http://msdn.microsoft.com/it-it/library/system.environment.stacktrace.aspx

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>