PC Review


Reply
Thread Tools Rate Thread

Determening where a function was called from

 
 
Christopher Kimbell
Guest
Posts: n/a
 
      24th Jun 2004
The Trace class in the .NET framework provides basic tracing capabilities. I
would like to create my own tracer that includes the date and time the trace
occured and what function and class the trace was called from.

The date and time is no problem, the tricky bit is to determine where the
function was called from, I only want to go one level up, not the whole call
stack. Is there any way to use reflection to determine the calling function?
I had a look at the MethodBase class but I can't find any promising
properties or methods. Since the call stack is used when getting the stack
trace from an exception and for security checks, I was hoping it would be
possible to get hold of something I could use.

Chris


 
Reply With Quote
 
 
 
 
Sunny
Guest
Posts: n/a
 
      24th Jun 2004
Hi Chris,


In article <(E-Mail Removed)>, (E-Mail Removed) says...
> The Trace class in the .NET framework provides basic tracing capabilities. I
> would like to create my own tracer that includes the date and time the trace
> occured and what function and class the trace was called from.
>
> The date and time is no problem, the tricky bit is to determine where the
> function was called from, I only want to go one level up, not the whole call
> stack. Is there any way to use reflection to determine the calling function?
> I had a look at the MethodBase class but I can't find any promising
> properties or methods. Since the call stack is used when getting the stack
> trace from an exception and for security checks, I was hoping it would be
> possible to get hold of something I could use.
>
> Chris
>


I'm using this:

private static string GetCallerInfo()
{
StackTrace st = new StackTrace(3);
return st.GetFrame(0).GetMethod().DeclaringType.FullName +
"." + st.GetFrame(0).GetMethod().Name;
}

Sunny
 
Reply With Quote
 
Christopher Kimbell
Guest
Posts: n/a
 
      24th Jun 2004
Thanks a bunch.

Chris

"Sunny" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Chris,
>
>
> In article <(E-Mail Removed)>, (E-Mail Removed) says...
> > The Trace class in the .NET framework provides basic tracing

capabilities. I
> > would like to create my own tracer that includes the date and time the

trace
> > occured and what function and class the trace was called from.
> >
> > The date and time is no problem, the tricky bit is to determine where

the
> > function was called from, I only want to go one level up, not the whole

call
> > stack. Is there any way to use reflection to determine the calling

function?
> > I had a look at the MethodBase class but I can't find any promising
> > properties or methods. Since the call stack is used when getting the

stack
> > trace from an exception and for security checks, I was hoping it would

be
> > possible to get hold of something I could use.
> >
> > Chris
> >

>
> I'm using this:
>
> private static string GetCallerInfo()
> {
> StackTrace st = new StackTrace(3);
> return st.GetFrame(0).GetMethod().DeclaringType.FullName +
> "." + st.GetFrame(0).GetMethod().Name;
> }
>
> Sunny



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Add-in function sometimes gets called twice Charles Williams Microsoft Excel Discussion 0 8th Jan 2010 12:39 AM
determening sheet number mark kubicki Microsoft Excel Programming 3 5th May 2005 12:10 AM
XLA function called twice Nigel Microsoft Excel Programming 0 16th Nov 2004 10:46 AM
Re: Possible to know who has called a function ? Robin Hammond Microsoft Excel Programming 0 5th Mar 2004 12:33 AM
How could the IRR function be called in C# Burton Wilkins Microsoft Dot NET Framework 0 25th Sep 2003 11:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:43 PM.