473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Trace/Logging Question

Hi,

I would like to output the source code module name and line number in some of my Trace.Writeline() calls. The information that I need is in the Environment.StackTrace string however I DO NOT want to issue a full stack trace and then parse a string every time I wish to Trace source code info!!!!!!!! For you ex-C++ now C# coders I wanna do something like this:

Trace.WriteLine(__FILE__ + "-" + __LINE__ + ": " + msg);

Is there a better way to get this info - say through reflection?? - without issuing a full stack trace every time I log information?

For extra credit does anybody know how to get the class & method name without issuing a full stack trace/parse????

--Richard

Nov 16 '05 #1
2 2080
Richard,

This will get you the current method and line number....

System.Diagnostics.StackTrace stack = new System.Diagnostics.StackTrace();
System.Diagnostics.StackFrame frame = stack.GetFrame(0);
Console.WriteLine("method name: " + frame.GetMethod().Name );
Console.WriteLine("line number: " + frame.GetFileLineNumber() );

Hope this helps,

~harris

"Richard" wrote:
Hi,

I would like to output the source code module name and line number in some of my Trace.Writeline() calls. The information that I need is in the Environment.StackTrace string however I DO NOT want to issue a full stack trace and then parse a string every time I wish to Trace source code info!!!!!!!! For you ex-C++ now C# coders I wanna do something like this:

Trace.WriteLine(__FILE__ + "-" + __LINE__ + ": " + msg);

Is there a better way to get this info - say through reflection?? - without issuing a full stack trace every time I log information?

For extra credit does anybody know how to get the class & method name without issuing a full stack trace/parse????

--Richard

Nov 16 '05 #2
Here is another possibility...

string theGoodStuff = System.Reflection.MethodBase.GetCurrentMethod().De claringType.FullName.ToString();

good luck,

~harris

"Richard" wrote:
Hi,

I would like to output the source code module name and line number in some of my Trace.Writeline() calls. The information that I need is in the Environment.StackTrace string however I DO NOT want to issue a full stack trace and then parse a string every time I wish to Trace source code info!!!!!!!! For you ex-C++ now C# coders I wanna do something like this:

Trace.WriteLine(__FILE__ + "-" + __LINE__ + ": " + msg);

Is there a better way to get this info - say through reflection?? - without issuing a full stack trace every time I log information?

For extra credit does anybody know how to get the class & method name without issuing a full stack trace/parse????

--Richard

Nov 16 '05 #3

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

Similar topics

2
by: Ken | last post by:
I would like to start using EventLogTraceListener, and am running into a couple of significant limitations: 1) I have found that there is no way to write EventLog entries with different...
6
by: latosca68 | last post by:
I need to demostrate, in a forensic job, that I can change (insert, update, delete) records in a table of an access database without trace. How can I do this ? I plan to make the queries or export...
4
by: Jazz | last post by:
Hello, I have a question about trace as MSDN seems confuses me.(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsTraceClassTopic.asp). My answer...
1
by: Champika Nirosh | last post by:
Hi, What is the different between System.Diagnostic.Trace and LogforNet.. if Trace is there to track error why this open source library is there.. Please clarify.. Nirosh.
5
by: who be dat? | last post by:
Hello all. I'm writing an application that is writing trace information that can be viewed in trace.axd. I would like to rename this and use a different name specific to my application. I know...
1
by: Patrick | last post by:
When Tracing in ASP.NET, the IIS process (on IIs5.1) is locking on the Trace file, and I can't read the trace file without restarting the IIS: Even the following does NOT work (how could I fix...
1
by: Pete Smith | last post by:
Hi, I'm looking for a Trace Class that logs errors to the Event Log and can send error reports to me via http. Each Trace Entry should contain the call stack, exception stack and line number...
8
by: Bryan | last post by:
Does anyone have an example of an application that can connect to a running process and capture Trace.WriteLine calls like in SQL Server Profiler? I know that we can inherit from a TraceListener...
7
by: amitos | last post by:
Hi! I consider using the Logging Application Block, Enterprise Library, Jan 2006 in a major project. To date, I've found that some of its features are not very well documented. One important...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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
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...

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.