Problem solve Get help with specific problems with your technologies, process and projects.

Use trace class to write certain log data to file during runtime based on execution flow

How to use trace class to write certain log data to file during runtime based on the execution flow.

This tip was submitted to the VS.NET Info Center by member Thomson Alexander. Please let other users know how useful it is by rating it below. Do you have a tip or code of your own you'd like to share? Submit it here.


Many of you have probably worked with reading and writing to file at run time in VB6. In .NET, we have a facility which makes the same easier. This is through two classes: one is trace class and other is debug class. I will be explaining trace class here.

Suppose you wanted to write certain log data to file during runtime based on the execution flow.

Code:

imports system.io
 dim objfilestream as nes system.io.filestream("c:test.log" ,system.io.filemode.openorcreate)
dim objtrace as new TextWriterTraceListener(objfilestream )

----in button click------
trace.listeners.add(objtrace)
trace.writeline("Error in proc A")
trace.flush()
--------
 'to flush the data  
'to file
'you can 
set   'trace.autoflush = true 
so that trace.flush need not be set each time.

You can use trace.writelineif method to check a certain condition before writing to a file.

Dig Deeper on Win Development Resources

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

TheServerSide.com

Close