473,654 Members | 3,280 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 3371
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.FrameCou nt; frameCount++)
{
sFrame = sTrace.GetFrame (frameCount);
MethodBase currentMethod = sFrame.GetMetho d();
//If the Type in the frame is the type that is being searched
if(currentMetho d.ReflectedType .FullName == current.FullNam e)
{
//get the method and its parameter info
//then exit out of the for loop
break;
}
}

Thanks again
CGuy
"CGuy" <cg**@csharp.ne t> wrote in message
news:OC******** ******@TK2MSFTN GP12.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.ne t> wrote in message news:<Ob******* *******@TK2MSFT NGP11.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.FrameCou nt; frameCount++)
{
sFrame = sTrace.GetFrame (frameCount);
MethodBase currentMethod = sFrame.GetMetho d();
//If the Type in the frame is the type that is being searched
if(currentMetho d.ReflectedType .FullName == current.FullNam e)
{
//get the method and its parameter info
//then exit out of the for loop
break;
}
}

Thanks again
CGuy
"CGuy" <cg**@csharp.ne t> wrote in message
news:OC******** ******@TK2MSFTN GP12.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 example, public void Method1() { Trace.WriteLine("Sample Text"); }
8
1183
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 Load event (gVars=new cGlobals;). Now, I can access gVars in my main form, but not from any other form. Do I need to add anything to my cGlobals.cs file to allow all forms to access the class? I've seen references to friend/internal etc., but am...
6
1302
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
1268
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 object of class2 and calling method of class2. class2 has one member of type class1.
0
873
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 different functions in VC++ for
7
2203
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 : 1. Connection object is a reference type object . 2. All reference types are passed by reference even when done without using modifier like ref / out .
4
1393
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 way attribute is set as i don't want any return value from that method. What i observered is when my window application start calling web method asynchronoysly
3
1701
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 processing some URL's asynchronously. Say in thread procedure for validating url through webrequest i am
4
2878
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
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8708
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7307
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
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 we have to send another system
1
1916
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.