Write to a log file using a new thread 
Author Message
 Write to a log file using a new thread

I would like to write to a log file everytime a user performs a function in
my app. This will only be used for debugging purposes, and the amount of
information being written would be very high.

Therefore it needs to be in a new thread. How can I send information from
the main apps functions to the thread so it can write to the log file. I do
not want to create a thread everytime the user performs a function I would
like to create 1 thread when the app starts and just pass information to it.

EG..

User starts application, the logging thread is created, from here on out
everything done in the main application is sent to the logging thread. When
the user click a command button it would pass "frmMain, function
'OpenStaff', cmdOpen CLICKED" and the logging thread would recieve this text
and write to the log file.



Mon, 06 Dec 2004 04:54:19 GMT  
 Write to a log file using a new thread
Hi Michael,

this is the structure i could use to solve your problem:

1. program starts from <sub Main>
2. the user form object is <UserForm>
3. <LogCommandID> is the integer variable we are using to pass log commands.
You set this variable to a non-zero value when user interacts with UserForm
(through command buttons or something)
4. <AppendToLog(LogCommandID%)> is the procedure to printout your log data

Public LogCommandID%

Sub Main
   LogCommandID = 0
   UserForm.Show                     (=NOT modal, execution continues)
   Do
       If (LogCommandID=0) Then
          DoEvents
       Else
          AppendToLog(LogCommandID)
          LogCommandID = 0
       End If
   Loop
End Sub

Dont forget to end the program through the Unload event of UserForm (or put
a control variable to the Do..Loop)



Quote:
> I would like to write to a log file everytime a user performs a function
in
> my app. This will only be used for debugging purposes, and the amount of
> information being written would be very high.

> Therefore it needs to be in a new thread. How can I send information from
> the main apps functions to the thread so it can write to the log file. I
do
> not want to create a thread everytime the user performs a function I would
> like to create 1 thread when the app starts and just pass information to
it.

> EG..

> User starts application, the logging thread is created, from here on out
> everything done in the main application is sent to the logging thread.
When
> the user click a command button it would pass "frmMain, function
> 'OpenStaff', cmdOpen CLICKED" and the logging thread would recieve this
text
> and write to the log file.



Mon, 06 Dec 2004 08:06:39 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Writing to a File in a New Thread

2. Making an Event Log Message File in VB (NOT WRITING TO THE EVENT LOG)

3. VBA - Write To File - Simple Log File!

4. Opening a form in a new thread, appart from the Apps main thread

5. Write in the application log or system log

6. Event Log: Writing to the NT Event Log

7. Write in Application Log or System Log on NT

8. Create a new Process thread in ASP using vb script

9. Writing log file.....

10. Write URLs to a log file?

11. Creating And Writing To An Error Log File

12. Writing Log Files on Shared Server

 

 
Powered by phpBB® Forum Software