473,791 Members | 2,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Logging runtime values passed to a function

Hi, I want to write down a function entry point logging method, allowing
logging of passed in parameters values along with function name and parameter
names. I know I can get the parameter name and function name using
System.Reflecti on or StackFrame but not sure if if it's possible to retreive
runtime passed in actual parameter values in .net 1.1 ?

e.g.
class User
{
public string GetName(int userId)
{
//Logging function, which logs function name and parameters values e.g. in
this case GetName and whatever calling code has passed in for userId

rest of function code

}
Mar 27 '06 #1
2 4040
>but not sure if if it's possible to retreive
runtime passed in actual parameter values in .net 1.1 ?


Not without explicitly naming them.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 27 '06 #2
thanks Mattias, I am using params object[] to dynamically log runtime value.
Following is the sample code. Please let me know if you think any other
better approach to solve this issue. Arif

////////////////////Sample code/////////////////////////////////
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//Sample One
int val = 10;
string name = "Arif";
BusinessFunctio n1(val,name);

//Sampe Two
int b = 10;
string name2 ="Test";
bool check = true;
BusinessFunctio n2(b,name2,chec k);
}

static void BusinessFunctio n1(int val, string name)
{
LogTrace(val,na me);
}
static void BusinessFunctio n2(int b, string name2, bool check)
{
LogTrace(b,name 2,check);
}

public static void LogTrace(params object[] args)
{
StackTrace callStack = new StackTrace(1, true);
StackFrame callingMethodFr ame = callStack.GetFr ame(0);

if (args == null || args.Length == 0)
{
Console.WriteLi ne("no parameters");
}
else
{
MethodBase callingMethod = callingMethodFr ame.GetMethod() ;
ParameterInfo[] parameters = callingMethod.G etParameters();

int inParamCount = parameters.Leng th;
foreach (ParameterInfo parameter in parameters)
if (parameter.IsOu t) inParamCount--;

Debug.Assert(in ParamCount == args.Length, String.Format(" Incorrect
number of arguments. Expected {0} but was {1}.", parameters.Leng th,
args.Length));

int paramCount = parameters.Leng th;
int argIndex = 0;
for (int i = 0; i < paramCount; i++)
{
Console.WriteLi ne(parameters[i].Name);
if (parameters[i].IsOut)
Console.WriteLi ne("<Unknown>") ;
else
{
if (args[argIndex] == null)
Console.WriteLi ne("<null>");
else
{
Console.WriteLi ne(args[argIndex].ToString().Tri m());
}
argIndex++;
}
if (i < paramCount - 1)
Console.WriteLi ne(",");
}
}
}
}

"Mattias Sjögren" wrote:
but not sure if if it's possible to retreive
runtime passed in actual parameter values in .net 1.1 ?


Not without explicitly naming them.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Mar 28 '06 #3

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

Similar topics

15
2988
by: Stefan Behnel | last post by:
Hi! I'm trying to do this in Py2.4b1: ------------------------------- import logging values = {'test':'bla'} logging.log(logging.FATAL, 'Test is %(test)s', values) -------------------------------
1
6028
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that required fields in a form have values. I'm writing the values to the client using document.write only so that I can confirm that the values are there to be played with - this is not the final result so please (unless it's leading to the script failure)...
3
14953
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
16
2177
by: Einar Høst | last post by:
Hi, I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some more experienced loggers can provide me with some ideas as to how to log in a simple yet flexible manner. For instance, I'd like the code to be as uncluttered as possible by Trace statements. As an example of basic logging functionality, I've come...
5
7463
by: Ram | last post by:
Hi Friends I want to develope a custom control in .net which can be used with any project. I am writing a function in that class which I want to take any object as parameter. For that I have used Object class as parameter. Now it can take any object as its parameter. But the problem is that I want to access the values of the private or public member variables of the passed object, for which I may have to typecast the Object class...
18
4360
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters, isn't easy. As far as I can see, there are only two solutions: 1) This one is portable. If...
0
1570
by: Yong | last post by:
I have a COM DLL written in C++ which worked fine when called from VB6. But we have now moved to Visual Studio 2005 - .NET Framework v2 and Windows XP Pro. In total there are 4 methods in this DLL which I can call, 3 of which have no return paramters as arguments (ByRef), these work fine, its only the method that uses 2 passed in paramters (Long - ByRef) to return the the required data that causes an exception. So from my VB.NET program:...
4
3332
by: Frank Aune | last post by:
Hello, I've been playing with the python logging module lately, and I manage to log to both stderr and MySQL database. What I'm wondering, is if its possible to specify the database handler in a config file like: class=DBHandler
2
1963
by: Vinay Sajip | last post by:
Some users of the logging package have raised an issue regarding the difficulty of passing additional contextual information when logging. For example, the developer of a networked application may want to log, in addition to specifics related to to the network service being provided, information about the IP address of the remote machine and the username of the person logged into and using the service. Python 2.4 introduced an 'extra'...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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
10155
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
9029
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
6776
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();...
1
4110
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
2
3718
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.