Search:
Namespaces
Discussions
.NET v1.1
Feedback
Establishing a Function name
Messages
Related Types
This message was discovered on
ASPFriends.com 'ngfx-compiledynamic' list
.
Julian Voelcker
-- Copied from [aspngcs] to [ngfx-compiledynamic] by Chaz <
Click here to reveal e-mail address
> --
I want to be able to call a class for logging info to a file with the
filename being tied into the function where the logging is occurring.
When I call the class using something like:
WriteLog.Log(FunctionName,stringToLog);
is there any way of determining the Function name automatically?
Cheers,
Julian Voelcker
The Virtual World (UK) Limited
Cirencester, United Kingdom
Reply to this message...
Jason Hall
I know that in an exception object, you get stack information, that can be
parsed to get the top most/bottom most etc.
Maybe try looking at the "System.Threading.
Thread
.CurrentThread" object. Or
try looking at reflection, though I doubt anything in reflection will keep
track of what function is currently running.
However, seeing as how it's included in exceptions, it has to be kept
someplace, good luck.
[Original message clipped]
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
Reply to this message...
Russ McClelland
There is a package called Diagnostics (I believe) that gives you the
StackFrame
object and others. This should be what you need...
-----Original Message-----
From: Jason Hall [mailto:
Click here to reveal e-mail address
]=20
Sent: Monday, May 06, 2002 6:24 PM
To: ngfx-compiledynamic
Subject: [ngfx-compiledynamic] Re: Establishing a Function name
I know that in an exception object, you get stack information, that can
be=20
parsed to get the top most/bottom most etc.
Maybe try looking at the "System.Threading.
Thread
.CurrentThread" object.
Or=20
try looking at reflection, though I doubt anything in reflection will
keep=20
track of what function is currently running.
However, seeing as how it's included in exceptions, it has to be kept=20
someplace, good luck.
[Original message clipped]
_________________________________________________________________
Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp
.
| [ngfx-compiledynamic] member
Click here to reveal e-mail address
=3D YOUR ID =
|
http://www.aspfriends.com/aspfriends/ngfx-compiledynamic.asp
=3D=20
| JOIN/QUIT
Reply to this message...
Julian Voelcker
Thanks Jason and Russ.
Unfortunately I'm not sure that I understand.
To explain in more detail.
I have a class that I use for logging events on a website called
WriteLog.
Within the class there is a method called Log that writes the
information to a file on the server.
I am currently passing the method the name of the file to write to, but
want to streamline the code by setting the name of the file to the name
of the function that called it.
For example: I have a method called SqlDb.ExQry() that executes a SQL
query that calls the WriteLog.Log() method twice to write the query
string to the log fine and then write the returned results of the
query.
When the WriteLog.Log() method is called, is there any way that I can
get it to work out the name of the method that called it i.e. ExQry or
SqlDb.ExQry?
Cheers,
Julian Voelcker
The Virtual World (UK) Limited
Cirencester, United Kingdom
Reply to this message...
Russ McClelland
Yes, that is exactly what the
StackFrame
object gets you. There is
another class along with
StackFrame
(I don't recall the name and don't
have .Net loaded at home yet). The collection gives you the current
execution stack. Inside your Log(), you can "get" the current execution
stack and look "backwars" one
StackFrame
to get the caller.
-----Original Message-----
From: Julian Voelcker [mailto:
Click here to reveal e-mail address
]=20
Sent: Tuesday, May 07, 2002 6:27 AM
To: ngfx-compiledynamic
Subject: [ngfx-compiledynamic] Re: Establishing a Function name
Thanks Jason and Russ.
Unfortunately I'm not sure that I understand.
To explain in more detail.
I have a class that I use for logging events on a website called=20
WriteLog.
Within the class there is a method called Log that writes the=20
information to a file on the server.
I am currently passing the method the name of the file to write to, but=20
want to streamline the code by setting the name of the file to the name=20
of the function that called it.
For example: I have a method called SqlDb.ExQry() that executes a SQL=20
query that calls the WriteLog.Log() method twice to write the query=20
string to the log fine and then write the returned results of the=20
query.
When the WriteLog.Log() method is called, is there any way that I can=20
get it to work out the name of the method that called it i.e. ExQry or=20
SqlDb.ExQry?
Cheers,
Julian Voelcker
The Virtual World (UK) Limited
Cirencester, United Kingdom
| [ngfx-compiledynamic] member
Click here to reveal e-mail address
=3D YOUR ID =
|
http://www.aspfriends.com/aspfriends/ngfx-compiledynamic.asp
=3D=20
| JOIN/QUIT
Reply to this message...
System.Diagnostics.StackFrame
System.Threading.Thread
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com