By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,668 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,668 IT Pros & Developers. It's quick & easy.

How do I get info regarding the calling method

P: n/a
Hi,

I'm trying to implement a custom trace listener. I would like the
WriteLine method of this tracelistener to also write out information
regarding the method from which Trace was called. For example,

public void Method1()
{
Trace.WriteLine("Sample Text");
}

public void Method2()
{
Trace.WriteLine("Sample Text");
}

Executing the aboce 2 Trace.WriteLine methods should also give me the name
of the method and its signature in the trace listener

Regards,
CGuy

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Thank you guys..

Here is how I finally did it

sTrace = new StackTrace(true);
//loop through all the stack frames
for(Int32 frameCount = 0; frameCount < sTrace.FrameCount; frameCount++)
{
sFrame = sTrace.GetFrame(frameCount);
MethodBase currentMethod = sFrame.GetMethod();
//If the Type in the frame is the type that is being searched
if(currentMethod.ReflectedType.FullName == current.FullName)
{
//get the method and its parameter info
//then exit out of the for loop
break;
}
}

Thanks again
CGuy
"CGuy" <cg**@csharp.net> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
Hi,

I'm trying to implement a custom trace listener. I would like the
WriteLine method of this tracelistener to also write out information
regarding the method from which Trace was called. For example,

public void Method1()
{
Trace.WriteLine("Sample Text");
}

public void Method2()
{
Trace.WriteLine("Sample Text");
}

Executing the aboce 2 Trace.WriteLine methods should also give me the name
of the method and its signature in the trace listener

Regards,
CGuy

Nov 13 '05 #2

P: n/a
I would like to use this bit of code but am having trouble
working out how the variable current is deriver. Can you please advise..

"CGuy" <cg**@csharp.net> wrote in message news:<Ob**************@TK2MSFTNGP11.phx.gbl>...
Thank you guys..

Here is how I finally did it

sTrace = new StackTrace(true);
//loop through all the stack frames
for(Int32 frameCount = 0; frameCount < sTrace.FrameCount; frameCount++)
{
sFrame = sTrace.GetFrame(frameCount);
MethodBase currentMethod = sFrame.GetMethod();
//If the Type in the frame is the type that is being searched
if(currentMethod.ReflectedType.FullName == current.FullName)
{
//get the method and its parameter info
//then exit out of the for loop
break;
}
}

Thanks again
CGuy
"CGuy" <cg**@csharp.net> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
Hi,

I'm trying to implement a custom trace listener. I would like the
WriteLine method of this tracelistener to also write out information
regarding the method from which Trace was called. For example,

public void Method1()
{
Trace.WriteLine("Sample Text");
}

public void Method2()
{
Trace.WriteLine("Sample Text");
}

Executing the aboce 2 Trace.WriteLine methods should also give me the name
of the method and its signature in the trace listener

Regards,
CGuy

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.