473,499 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automatically generate a string of the namespace, class, function/procedure.

Is there anyway to generate a string that contains the name of the
namespace, the object name and then the function/procedure name that is
currently running.

I want to use this for logging information and am getting tired of having to
type/cut-paste the things.

If I can't get it all, can I get at least some of it?

TIA - Jeff.
Sep 12 '07 #1
2 1379
"Mufasa" <jb@nowhere.comwrote in message
news:O3**************@TK2MSFTNGP05.phx.gbl...
Is there anyway to generate a string that contains the name of the
namespace, the object name and then the function/procedure name that is
currently running.
You can use the StackTrace class to get the last StackFrame in the
stack. This has a GetMethod() method which will give you the information
that you want.

Note, however, that this is not a fast operation, so you will not want
to leave this permanently active inside your methods.

Sep 12 '07 #2
On Sep 12, 3:08 pm, "Mufasa" <j...@nowhere.comwrote:
Is there anyway to generate a string that contains the name of the
namespace, the object name and then the function/procedure name that is
currently running.

I want to use this for logging information and am getting tired of having to
type/cut-paste the things.

If I can't get it all, can I get at least some of it?

TIA - Jeff.
Here is a C# example:
static void Main(string[] args)
{
System.Diagnostics.StackFrame sf = new
System.Diagnostics.StackFrame(true);
string fileName = sf.GetFileName();
string lineNumber = sf.GetFileLineNumber().ToString();
string methodName = sf.GetMethod().Name;

string output = string.Format("File name={0} , Line
number={1} , Method name={2}", fileName, lineNumber, methodName);
Console.WriteLine(output);
}

Sep 12 '07 #3

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

Similar topics

8
2182
by: Filip Dreger | last post by:
Each function has a func_code property that is suposed to contain the pure bytecode of the function. All the context (including reference to relevant namespaces) is stored in different fields of...
0
410
by: Daniel Lidström | last post by:
Hi, I've been trying a long time now to generate some XML using MC++ and XmlSerializer. I have a piece of C# code that produces exactly what I want, but I simply can't get the MC++ code to write...
2
6894
by: PeterW | last post by:
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as...
1
11178
by: Jeffrey B. Holtz | last post by:
I'm trying to get the Name of the USB device pluged in from the RegisterDeviceNotification that I've used P/Invoke to marshal. I have seen a similar posting on the VisualBasic newgroups but I do...
7
7895
by: Steven.Xu | last post by:
Hello everyone! I have a problem about create an instance automatically in C#. Now I have a class: namespace1.namespace11.CClass01. I want to create it's instance in a function named...
6
3352
by: cpnet | last post by:
I've authored a custom web component (a non-ui component kinda like a DataSet) and so far it's working. When my web component is added to the web form in the designer from the toolbox, the...
0
5085
by: Richard Gregory | last post by:
Hi, I have the wsdl below, for an Axis web service, and when I select Add Web Refernce in Visual Studio the proxy is missing a class representing the returnedElementsType (see reference.cs below...
9
2081
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
8
7021
by: Les Caudle | last post by:
Using this command line to run XSD.exe xsd /c /o:outputDir input.xsd /f on the following XSD <?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema"...
0
7007
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...
0
7220
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
6893
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
7386
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
5468
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,...
0
4599
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...
0
3098
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
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.