Log

 Public Shared Sub WriteLog(ByVal FormID As String, ByVal ex1 As Exception)
'log信息
Dim loginfo As String = "" '获取现在的时间
Dim strDate As String
strDate = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") '获取画面ID
Dim strFormId As String
strFormId = FormID '获取路径
Dim path As String
path = Application.StartupPath.ToString.Split(":\")().ToString() & ": " & "\REMSLOG" If Not My.Computer.FileSystem.DirectoryExists(path) Then
My.Computer.FileSystem.CreateDirectory(path)
End If path &= "\Err.log" loginfo = strDate + System.Environment.NewLine + strFormId + ":" Dim SW As System.IO.StreamWriter = Nothing
Try
SW = New System.IO.StreamWriter(path, True)
SW.WriteLine(loginfo)
SW.WriteLine("Err Info:" & ex1.Message)
SW.WriteLine("Err Source:" & ex1.StackTrace)
SW.WriteLine("Err Function:" & ex1.TargetSite.Name)
Catch ex As Exception
Finally
If Not SW Is Nothing Then
SW.Flush()
SW.Close()
End If
End Try
End Sub

Try--Catch中直接调用该方法即可。

上一篇:Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds...


下一篇:安卓Design包之TabLayout控件的简单使用