473,503 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I get info regarding the calling method

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

Jul 19 '05 #1
2 3366
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

Jul 19 '05 #2
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

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
307
by: CGuy | last post by:
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...
8
1172
by: John Young | last post by:
Hi, I have a class (cGlobals.cs) which I create in my main form (frmMain). I have declared a variable at the top of my frmMain class (cGlobals gVars;). I then create an instance in my forms...
6
1289
by: Luca | last post by:
I have a doubt: is it dangerous to create widgets out of the main thread, or it is dangerous to call methods of a widgets out of the thread which created it? or both? TIA Perry
7
1257
by: trialproduct2004 | last post by:
Hi all I am having application which has three classes. in one class say class1, i am having arraylist where i am adding and removing string. there is one method in class1 which is creating...
0
862
by: Vijay | last post by:
Hi, I want to implement a DDE server in VC++ and then use it from a Java application to provide real time data to excel or any other DDE client . For this a dll was created with 3...
7
2196
by: Mrinal Kamboj | last post by:
Hi , I am using OracleConnection object from Oracle ODP.net provider and following is the behaviour which i am finding bit strange : To start with my argument is based on followings facts : ...
4
1383
by: archana | last post by:
Hi all, I am having one confusion regarding invoking web method of web service asychronously through windows applicaiton. What i am doing is i am having one long runing web method whose one...
3
1696
by: archana | last post by:
Hi all, I have one confusion regarding threading in windows service which is developed in c#. What i am doing is on 'onstart' event i am starting one thread. In thread procedure i am...
4
2868
by: mfc | last post by:
How do i get the type info in a static method? for instance in the code below is it possible for the Method to get the type to know what type was used to call Method? thanks class C {
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.