Get class- and functionname

  • Thread starter Thread starter sewid
  • Start date Start date
S

sewid

Hi!

Is there a possibility to get the class- and the functionname from the
current function? I want to log all exceptions with the class and the
function, where the exception occured. So I created a function
logException(string message, string classname, string functionname)
and it would be really cool to fill the classname and functionname
automatically.

Best regards,
Sebastian
 
Is there a possibility to get the class- and the functionname from the
current function? I want to log all exceptions with the class and the
function, where the exception occured. So I created a function
logException(string message, string classname, string functionname)
and it would be really cool to fill the classname and functionname
automatically.

See MethodBase.GetCurrentMethod.

Jon
 
Is there a possibility to get the class- and the functionname from the
current function? I want to log all exceptions with the class and the
function, where the exception occured. So I created a function
logException(string message, string classname, string functionname)
and it would be really cool to fill the classname and functionname
automatically.

Scratch previous response - if you call it from LogException, it'll
return LogException :) You probably want the StackTrace class.

Note that other people have already done a lot of this work for you -
look at the log4net framework.

Jon
 
Jon said:
Scratch previous response - if you call it from LogException, it'll
return LogException :) You probably want the StackTrace class.

Note that other people have already done a lot of this work for you -
look at the log4net framework.

Jon

If he's logging exceptions, isn't what he want already provided in the
stack trace of the exception object?

In other words, if he attempts to use StackTrace or similar, he will be
logging where the logging occured, not where the exception occured.

Or am I missing something? (I bet I am)
 
Jon said:
Scratch previous response - if you call it from LogException, it'll
return LogException :) You probably want the StackTrace class.

Note that other people have already done a lot of this work for you -
look at the log4net framework.

Jon

If he's logging exceptions, isn't what he want already provided in the
stack trace of the exception object?

In other words, if he attempts to use StackTrace or similar, he will be
logging where the logging occured, not where the exception occured.

Or am I missing something? (I bet I am)
 
Jon said:
Scratch previous response - if you call it from LogException, it'll
return LogException :) You probably want the StackTrace class.

Note that other people have already done a lot of this work for you -
look at the log4net framework.

Jon

If he's logging exceptions, isn't what he want already provided in the
stack trace of the exception object?

In other words, if he attempts to use StackTrace or similar, he will be
logging where the logging occured, not where the exception occured.

Or am I missing something? (I bet I am)
 
Or am I missing something? (I bet I am)

Nope, not really - it was me missing that :)

Unless of course he wants to log where it was caught as well as where
it was thrown.

Jon
 
Lasse said:
If he's logging exceptions, isn't what he want already provided in the
stack trace of the exception object?

In other words, if he attempts to use StackTrace or similar, he will be
logging where the logging occured, not where the exception occured.

Or am I missing something? (I bet I am)

Sorry about the multiple replies. I had inadvertantly hit "Reply all",
which included Jon's email in the to-list, and my email server
apparently doesn't like Thunderbird, so I hit send 2 times before I
noticed :)

(Hope I didn't spam Jon in the process)
 
Back
Top