Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Capturing Current Method

Started by coolblue Aug 1, 2006 at 4:36 AM 2 replies 450+ views
Original Post
coolblue
coolblue
I am attempting to write an error logger and I need to capture the method that threw the error. The exception only contains the deeper down methods that caused the error. Say my method is called 'InsertData' and it calls a stored procedure. I want my logger to record that 'InsertData' caused the error not 'Void OnError(System.Data.SqlClient.SqlException, Boolean)'.
coolblue
coolblue
Found it!!

If anyone is interested I did it by using:-

string methodStr=System.Reflection.MethodBase.GetCurrentMethod().ToString();
Saandman
Saandman
The Exception object holds the name of the method that threw the exception, works for me :)

ex.TargetSite.Name
________pro.gram.mer - an organism that turns caffeine into code
coolblue
coolblue
As I posted originally, the ex.TargetSite.Name only gives me deep down info eg 'Void OnError(System.Data.SqlClient.SqlException, Boolean)'. I need this to report back on the method I wrote to call the storedprocedure in the first place.

Reflection has solved the problem though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.