Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Get class- and functionname

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sewid - 28 Jan 2008 10:57 GMT
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
Jon Skeet [C# MVP] - 28 Jan 2008 11:02 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
> 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
Jon Skeet [C# MVP] - 28 Jan 2008 11:03 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
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.