乙個操作日誌檔案的類

2021-04-02 13:26:14 字數 1185 閱讀 2636

在軟體中常用到日誌檔案,這是我在專案中用到的乙個操作日誌檔案的類。

imports system

imports system.io

public class classlogfile

inherits system.object

public shared logfilename as string

public sub writelog(byval logstring as string)

dim path as string = "log.txt"

dim sw as streamwriter

' this text is added only once to the file.

if file.exists(path) = false then

' create a file to write to.

sw = file.createtext(path)

sw.writeline("本日誌檔案記錄了您的日常操作的重要資訊!對您的應用有重要的幫助作用!")

sw.flush()

sw.close()

end if

'清理當前編寫器的所有緩衝區,並使所有緩衝資料寫入基礎流。

sw.flush()

sw.close()

end sub

public sub readlogwithnotepad() 'byval path as string)

' open the file to read from.

trywritelog("查閱log")

system.diagnostics.process.start("log.txt")

catch ex as exception

msgbox(ex.message)

end try

end sub

public sub clearlog()

system.io.file.delete("log.txt")

writelog("  清空log")

end sub

end class

' 使用例項:

'例項化 日誌檔案

module1.glogfile = new classlogfile

'記錄日誌

glogfile.writelog("系統啟動")

乙個簡單的日誌類

放乙個以前做的,一直用著的日誌類。比較短,也不用碼很多字去說明,如下 1 2 日誌類 log.cs34 5 用法 6 ningtao.log mylog new ningtao.log 日誌名稱 7 mylog.addlog 日誌資訊 8 新增一條日誌時 9 目錄結構 日誌名稱 年月 日.log 1...

乙個簡單的日誌封裝類

記錄乙個自己封裝的日誌類,不完善的地方,望指點。其中,包含寫檔案和輸出到終點,定義日誌等級,定義日誌儲存檔案時間間隔,日誌檔案個數等 並統一日誌輸出格式 檔名,方法名等資訊 import logging from logging import handlers class logger object...

開源乙個C C 日誌類

日誌類可以作為乙個練手專案,實現乙個好的日誌類並不容易,這裡先出第乙個版本,後期持續優化。功能簡單對於新手非常友好,歡迎指正錯誤。該日誌類我命名為cclog,第乙個c是class的意思,忽略這一點的話可以叫clog。作用當然是日誌記錄,寫日誌操作是執行緒安全的,支援類似字串format的形式。基於w...