Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Logging issue

Logging issue

Logging issue

Been running a simple one Form VB EXP 2k8 app for several years which monitors a Serial Port data stream, updates some indicators on the Main Form, and captures specific key entries to forward back to the serial port ... I recently added some Roll over Balloons, a Help Form, and some Data Logging. At issue; the app now runs for around 8 hours then crashes with system level exception error (no error code) ... if I remove the code with a remark ' the app is stable again.

Data logging is done by calling me.DebugPrint instead of debug.print where DebugPrint checks a my.settings.LogFlag to determine if a logging is enabled ... log files are also only 1 day in length at 00:05 the current log file overwrites the previous days log file and a fresh log file is started

1) is there any way to determine what is actually failing

2) perhaps there is a better way to do the logging

Private Sub DebugPrint(ByRef stDebug As String)
Do While gloLock
If My.Settings.LogFlag And My.Settings.LogFile & "" <> "" Then
My.Computer.FileSystem.WriteAllText(My.Settings.LogFile, stDebug & vbCrLf, True)
End If
End Sub

Private Sub mvLogFile()
Dim src As String
Dim dst As String
src = My.Settings.LogFile
dst = src & ".bak"

Me.DebugPrint("Move: " & src & " - " & dst)

gloLock = True

If System.IO.File.Exists(dst) = True Then
End If

If System.IO.File.Exists(src) = True Then
System.IO.File.Move(src, dst)
End If

gloLock = False
End Sub

RE: Logging issue

My guess is that gloLock is getting set to True, then there's an (unhandled) error either deleting or moving one of the files so gloLock never gets reset back to False, which produces an endless loop in DebugPrint.

Throw in some Try...Catch code and write any error messages to a separate log file.

Also, I think you should look into using System.IO.StreamWriter to write your log files.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: Logging issue

Thanks ... added try catch surrounding logic in both DebugPrint and mvLogFile last night

1) gloLock (global Boolean) is defined in the Form Class header and is only set/cleared once a day at 00:05:00 in the mvLogFile logic ... the intent of the lock is to ensure the DebugPrint can't write a log during a move event

2) with the app running in debug mode, the log file has grown to 300K+ in the last 10 hours

3) the Catch has captured debug.print("dp err: " & stDebug) errors and displayed them on the immediate window showing that
a) there are numerous errors at random times
b) the content of stDebug isn't suspect ... comparison of log file shows similar messages are being logged
c) all "db err:" errors are being preceded with
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll

4) downloaded and installed Visual Studio 2017, the converted app appears to misbehave in the same way

5) this app runs on three platforms XP, W7 and WX all appear to have the same issue with logging

found an example for possibly expanding the exception error ... going to try this to see if there is more information on these errors ... plus will look at using StreamWriter

RE: Logging issue

Ok ... so the exception errors appear to be too many events calling debugprint at the same time ... the exception error is stating the log file in use by another user ... meaning one log event hasn't completed when another one is being requested ... surely there has to be a basic way to prevent this in an event driven app?

Perhaps one has to build a FIFO logger where the app routines push messages and a timed logger event pops messages and exports them to file

RE: Logging issue

ok just added another global flag surrounding the LOG to FILE logic which may work provided:
- WriteAllText doesn't return control to the event before it closes the log file
- there isn't a lag with the OS disk routines
- not sure how VB does reentrant/multithreaded events where 2 entries on separate threads might attempt to lock gloWL at the same time

do while gloWL
gloWL = True
My.Computer.FileSystem.WriteAllText(My.Settings.LogFile, stVal & vbCrLf, True)
gloWL = False

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close