Imports System.Text Namespace DebugLog Public Class DebugPrintClass Enum DebugPrintType System Comport Database NetWork Ftp End Enum ''' ''' 显示所有数据,优先度最高 ''' ''' Public Shared Property ShowAllData() As Boolean = True ''' ''' 是否显示系统信息 ''' ''' Public Shared Property ShowSystemData() As Byte = 1 ''' ''' 是否显示串口信息 ''' ''' Public Shared Property ShowComportData() As Byte = 1 ''' ''' 是否显示数据库信息 ''' ''' Public Shared Property ShowDatabaseData() As Byte = 1 ''' ''' 是否显示网络信息 ''' ''' Public Shared Property ShowNetWorkData() As Byte = 1 ''' ''' 是否显示Ftp信息 ''' ''' Public Shared Property ShowFtpData() As Byte = 1 ''' ''' 显示信息的集合,对应数据位为1则打印,为0不打印 ''' ''' Public Shared Property ShowDataType() As Integer = ShowSystemData >> DebugPrintType.System Or ShowComportData >> DebugPrintType.Comport Or ShowDatabaseData >> DebugPrintType.Database Or ShowNetWorkData >> DebugPrintType.NetWork Or ShowFtpData >> DebugPrintType.Ftp ''' ''' 是否添加时间前缀 ''' ''' Public Shared Property ShowTime() As Boolean = True ''' ''' 是否显示与上包显示的间隔 ''' ''' Public Shared Property ShowTimeSpan() As Boolean = True Private Shared _lastShowTime As DateTime = Now Private Shared _timeSpan As TimeSpan ''' ''' 打印调试信息 ''' ''' 需要打印的信息 Private Shared Sub DebugPrint(printString As String) Console.WriteLine(printString) End Sub ''' ''' 打印调试信息 ''' ''' 打印信息类型 ''' 需要打印的信息 Public Shared Sub DebugPrint(type As DebugPrintType, printString As String) If ShowAllData = False Then Return If ((ShowDataType >> type) And 1) = 0 Then Return _timeSpan = Now - _lastShowTime _lastShowTime = Now Dim msgBuilder As New StringBuilder If ShowTime Then msgBuilder.Append($"{Now:yyyy-MM-dd HH:mm:ss} - ") If ShowTimeSpan Then msgBuilder.Append($"{_timeSpan.TotalMilliseconds,8} - ") msgBuilder.Append($"{type} - ") msgBuilder.Append($"{printString}") DebugPrint(msgBuilder.ToString()) End Sub ''' ''' 打印调试信息 ''' ''' 打印信息类型 ''' 需要打印信息的提示前缀 ''' 需要打印的信息 Public Shared Sub DebugPrint(type As DebugPrintType, tip As String, printString As String) DebugPrint(type, $"{tip}:{printString}") End Sub End Class End Namespace