> 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
Lasse Vågsæther Karlsen - 28 Jan 2008 14:26 GMT
>> 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
[quoted text clipped - 10 lines]
>
> 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)

Signature
Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Lasse Vågsæther Karlsen - 28 Jan 2008 14:26 GMT
>> 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
[quoted text clipped - 10 lines]
>
> 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)

Signature
Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Lasse Vågsæther Karlsen - 28 Jan 2008 14:27 GMT
>> 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
[quoted text clipped - 10 lines]
>
> 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)

Signature
Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Jon Skeet [C# MVP] - 28 Jan 2008 14:57 GMT
<snip>
> 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 Vågsæther Karlsen - 28 Jan 2008 15:06 GMT
>>> 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
[quoted text clipped - 18 lines]
>
> 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)

Signature
Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3