编写VB程序,当程序启动时,生成一条日志记录'很简单vb.net创建日志文件,添加一个过程 MyLog
'在 Form_Load 中加入 Call MyLog("启动")
'在 Form_Unload 中加入 Call MyLog("退出")
Private Sub Form_Load()
Call MyLog("启动")
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call MyLog("退出")
End Sub
Private Sub MyLog(nStr As String)
Dim F As String, H As Long
nStr = Format(Now, "yyyy-mm-dd hh:mm:ss")nStr
F = "C:\myprog.log"
'如果要将文件保存到与vb.net创建日志文件你vb.net创建日志文件的 exe 相同vb.net创建日志文件的文件夹vb.net创建日志文件 , 将上句改为 F = App.Path"\myprog.log"
【vb.net创建日志文件 vbnet createobject】H = FreeFile
Open F For Append As #H
Print #H, nStr
Close #H
End Sub
在vb.net 中,记录系统错误日志这个功能怎么实现Public Sub ShowError(strModule As String, strProcedure As String, lngErrorNumber As Long, strErrorDescription As String, showMsg As String)
'
'错误处理中心过程,写数据库日志表或写日志文件
'
'strModule'模块名称
'strProcedure'过程名称
'lngErrorNumber'错误ID号
'strErrorDescription '错误描述
'showMsg'是否显示本过程内错误显示信息(值:"Y" or "N")
'Error表结构(f001 (Date)发生时间,f002 (nvarchar50)模块名称, f003 (nvarchar50)过程名称, f004 (nvarchar50)错误ID号, _
f005 (nvarchar300)错误描述,f006 (nvarchar50)版 本 号, f007 (nvarchar50)用户名称, f008 (nvarchar50)网卡地址
'ErrorCode表结构 f001 (nvarchar20)错误代码,f002 (nvarchar255)错误信息, f003 (numeric9)错误级别
'级别说明: '10'以下,一般错误,不影响操作
''11-20',严重错误,不能操作,程序执行退出
On Error GoTo ErrorHandle
Dim strMessage As String
Dim strCaption As String
Dim sVer As String
Dim intLogFile As Integer
Dim Res As New ADODB.Recordset
Dim ResErrorCode As New ADODB.Recordset
Dim strSQL As String
'对应错误号,从ErrorCode表中找到对应的错误信息,0-1000 错误号保留给VB
DBOpen ResErrorCode, "select * from errorcode where f001='"lngErrorNumber"'"
If Not (ResErrorCode.EOF Or ResErrorCode.BOF) Then
strMessage = ResErrorCode.Fields("f002")
If ResErrorCode.Fields("f003")10 Then
MsgBox "产生一个严重错误,可能影响到系统的可操作性,请立即联系本系统开发人员!", vbCritical, "严重错误"
End If
End If
'写错误入文件----------------------------
intLogFile = FreeFile
Open App.Path"\"strIni.LogFile For Append As #intLogFile
Print #intLogFile, "***错误"; VBA.Now"*** ""Version:"_
str$(App.Major)"."str$(App.Minor)"."Format(App.Revision, "0000")
Print #intLogFile, "Error: "lngErrorNumber
Print #intLogFile, "Description: "strErrorDescription
Print #intLogFile, "Module: "strModule
Print #intLogFile, "Procedure: "strProcedure
Print #intLogFile, ""
Close #intLogFile
If Len(strMessage)2 Then strErrorDescription = strMessage
strMessage = "错误: ""("lngErrorNumber")"strErrorDescriptionvbCrLfvbCrLf_
"模块:"strModule";过程:"strProcedure
sVer = Trim(str$(App.Major)"."str$(App.Minor)"."_
Format(App.Revision, "0000"))
strCaption = "错误 Version: "sVer
'写错误入数据库表--------------------------
strSQL = "insert into error(f001,f002,f003,f004,f005,f006,f007,f008) values(" _
DateFmtBVBA.NowDateFmtE"," _
IIf(Len(Trim(strModule)) = 0, "null", "'"strModule"'")"," _
IIf(Len(Trim(strProcedure)) = 0, "null", "'"strProcedure"'")"," _
IIf(Len(Trim(lngErrorNumber)) = 0, "null", "'"lngErrorNumber"'")"," _
IIf(Len(Trim(strErrorDescription)) = 0, "null", "'"Replace(strErrorDescription, "'", "")"'")"," _
推荐阅读
- 包含b站视频如何做ppt的词条
- 电视怎么选开关,电视哪个是开关
- python把字符串变成日期时间格式,python字符串转为datetime
- csgo国际服语言 csgo国际服语音变国服
- 如何做好新媒体十条戒律,如何做好新媒体十条戒律工作
- 扩容硬盘怎么弄正常,扩容硬盘恢复真实内存
- 虚拟机传文件,宿主机向虚拟机传文件
- vb.net教程哪家好 vbnet msdn
- 怎么制作潮图小程序视频,怎么制作潮图文字壁纸