vb.net出力日志的簡單介紹

vb.net編譯時生成log文件夾

在程序目錄下生成log目錄,用于保存日志文件。

成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供鳳臺網(wǎng)站建設(shè)、鳳臺做網(wǎng)站、鳳臺網(wǎng)站設(shè)計、鳳臺網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、鳳臺企業(yè)網(wǎng)站模板建站服務(wù),10余年鳳臺做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

自動在log目錄中,生成日志文件,文件命名用年月日定義,如20100119_log.log。

在日志文件中,每行記錄一個時間點的運行內(nèi)容,時間點的精度應(yīng)該達(dá)到毫秒。

請問誰知道怎么用vb.net 打印.log日志文件, 用代碼寫的,謝謝了,急用

Dim sw As StreamWriter = New StreamWriter(“c:\xxxxx.log”, True) 'true是指以追加的方式打開指定文件

For i = 0 To j

temp = i.ToString

sw.WriteLine(temp)

sw.Flush()

Next

sw.Close()

sw = Nothing

VB.NET做的程序在其它機器上運行時出現(xiàn)問題,求助!

缺少運行庫

裝上.NETframework

和帶上引用的插件(工程屬性那有個引用頁)

.

在vb.net 中,記錄系統(tǒng)錯誤日志這個功能怎么實現(xiàn)

Public Sub ShowError(strModule As String, strProcedure As String, lngErrorNumber As Long, strErrorDescription As String, showMsg As String)

'

'錯誤處理中心過程,寫數(shù)據(jù)庫日志表或?qū)懭罩疚募?/p>

'

'strModule '模塊名稱

'strProcedure '過程名稱

'lngErrorNumber '錯誤ID號

'strErrorDescription '錯誤描述

'showMsg '是否顯示本過程內(nèi)錯誤顯示信息(值:"Y" or "N")

'Error表結(jié)構(gòu)(f001 (Date)發(fā)生時間, f002 (nvarchar50)模塊名稱, f003 (nvarchar50)過程名稱, f004 (nvarchar50)錯誤ID號, _

f005 (nvarchar300)錯誤描述,f006 (nvarchar50)版 本 號, f007 (nvarchar50)用戶名稱, f008 (nvarchar50)網(wǎng)卡地址

'ErrorCode表結(jié)構(gòu) f001 (nvarchar20)錯誤代碼, f002 (nvarchar255)錯誤信息, f003 (numeric9)錯誤級別

' 級別說明: '10'以下,一般錯誤,不影響操作

' '11-20',嚴(yán)重錯誤,不能操作,程序執(zhí)行退出

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

'對應(yīng)錯誤號,從ErrorCode表中找到對應(yīng)的錯誤信息,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 "產(chǎn)生一個嚴(yán)重錯誤,可能影響到系統(tǒng)的可操作性,請立即聯(lián)系本系統(tǒng)開發(fā)人員!", vbCritical, "嚴(yán)重錯誤"

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 ")" strErrorDescription vbCrLf vbCrLf _

"模塊:" strModule "; 過程:" strProcedure

sVer = Trim(str$(App.Major) "." str$(App.Minor) "." _

Format(App.Revision, "0000"))

strCaption = "錯誤 Version: " sVer

'寫錯誤入數(shù)據(jù)庫表--------------------------

strSQL = "insert into error(f001,f002,f003,f004,f005,f006,f007,f008) values(" _

DateFmtB VBA.Now DateFmtE "," _

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, "'", "") "'") "," _

IIf(Len(Trim(sVer)) = 0, "null", "'" sVer "'") "," _

IIf(Len(Trim(sUserName)) = 0, "null", "'" sUserName "'") "," _

IIf(Len(Trim(sVer)) = 0, "null", "'" EthernetNO "'") ")"

Cn.Execute strSQL

'是否顯示未知錯誤信息

If Trim(UCase(showMsg)) = "Y" Then MsgBox strMessage, vbCritical, strCaption

PROC_EXIT:

Set Res = Nothing

Set ResErrorCode = Nothing

Exit Sub

ErrorHandle:

Resume Next

請教高手,如何用vb實現(xiàn)“使用日志”?

很多種方法,最常用的一是用文本文件或數(shù)據(jù)庫記錄,二是調(diào)用API函數(shù)直接寫入系統(tǒng)日志或應(yīng)用程序日志

當(dāng)前題目:vb.net出力日志的簡單介紹
網(wǎng)站URL:http://muchs.cn/article42/docscec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、網(wǎng)站改版網(wǎng)站制作、網(wǎng)站導(dǎo)航商城網(wǎng)站、網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名