how to write the exceptions in a text file??

bcm

Well-known member
Joined
Aug 13, 2007
Messages
56
Programming Experience
Beginner
:(can any one tell me how to write the errors/exceptions, occured while compiling vb.net program, in a text file?
IN VB.NET2003
:confused:
 
For my company (which doesn't really have the best exception logging rules) we have a single AppendLog routine that excepts a string and opens a streamwriter for the log file and simply writes the entry on a new line or lines.

All we do is something similar to: AppendLogFile("Calling routine name here: " & ex.ToString) where ex is the exception caught.

Not the best, but simple and does work.

Here's an example of one of our older AppendLog routines:
VB.NET:
Expand Collapse Copy
    Friend Function AppendLogFile(ByVal text As String)
        Dim done As Boolean = False
        Dim outtext As String
        If gblGame.Debugging Then
            If File.Exists(gblGame.LogFile) Then
                While Not done
                    Try
                        Dim myStreamWriter As StreamWriter
                        outtext = "Computer = <" & gblGame.PlayerList & ">" & (Now.ToLongTimeString)
                        outtext += text & vbCrLf
                        myStreamWriter = File.AppendText(gblGame.LogFile)
                        myStreamWriter.Write(outtext)
                        myStreamWriter.Flush()
                        myStreamWriter.Close()
                        done = True
                    Catch ex As Exception
                    End Try
                End While
            Else
                MsgBox("Attempted to Output This Message to Closed Log File: " & text)
            End If
        End If
    End Function

As for compiling, if there's errors then it wont compile in the first place and all you need to do is check the Errors and Warnings list in the IDE
 
Back
Top