Click here to Skip to main content
13,052,163 members (52,024 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 9 Nov 2011

Using a text listener to log messages

, 10 Nov 2011
Rate this:
Please Sign up or sign in to vote.
How to use the TextWriterTraceListener in

Here is a very simple way to log information from your program. It works by setting up a "listener" that will intercept any trace.write command and send them to the filestream that you open. I use this method to write diagnostic messages.

// Start.prg
#USING System.Diagnostics
    LOCAL objTraceListener AS TextWriterTraceListener
    LOCAL XferLog          AS FileStream
    LOCAL cFile            AS STRING
    cFile := "c:\test.log"
    // create the log file
    XferLog := 
cFile), System.IO.FileMode.Create}
    objTraceListener := System.Diagnostics.TextWriterTraceListener{XferLog}
    Trace.WriteLine("Starting Log")
    Trace.WriteLine("This is a test")
    Trace.WriteLine("Leaving Log File")
    // close our log file now that we are done
    IF (XferLog != NULL)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Willie Moore
Network Administrator AT&T
United States United States
Willie Moore is a ”Professional IT – Network Design” for AT&T located in Birmingham, Alabama. He is also the owner of wmConsulting. He has been programming in Clipper since Summer ’87 and has been producing applications in Visual Objects,, PHP,, and C# for the past 20 years He is a Microsoft Certified Systems Engineer and a Microsoft Certified Trainer. Willie can be reached on the Internet at

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 5 Good idea. Also, one of the first sa... Pin
GeorgeNT11-Nov-11 10:49
memberGeorgeNT11-Nov-11 10:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 10 Nov 2011
Article Copyright 2011 by Willie Moore
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid