VB.NET寫(xiě)Log方法詳細(xì)介紹
作者:佚名
VB.NET寫(xiě)Log方法的功能實(shí)現(xiàn),可以通過(guò)本文介紹的這樣一段代碼來(lái)實(shí)現(xiàn)。我們可以通過(guò)對(duì)這段代碼的解讀,詳細(xì)掌握其中的編寫(xiě)技巧。
如果我們想使用VB.NET進(jìn)行代碼編寫(xiě)的話,首先就要從基本概念開(kāi)始了解,然后通過(guò)不斷的實(shí)踐練習(xí)來(lái)積累一定的運(yùn)用經(jīng)驗(yàn),才能很好的通過(guò)這款語(yǔ)言來(lái)實(shí)現(xiàn)我們需要的各種需求。下面就先來(lái)了解一下有關(guān)VB.NET寫(xiě)Log方法的相關(guān)操作。#t#
最近在項(xiàng)目中有用到VB.NET寫(xiě)Log方法的功能.具體代碼如下:
Code
- Public Sub WriteLog()Sub
WriteLog(ByVal Msg As String) - Dim varAppPath As String
- varAppPath = System.AppDomain.
CurrentDomain.SetupInformation.
ApplicationBase + "log" - System.IO.Directory.CreateDirectory
(varAppPath) - Dim head As String
- head = System.DateTime.Now.Hour.
ToString() + ":" + System.DateTime.
Now.Minute.ToString() - headhead = head + ":" + System.DateTime.
Now.Second.ToString() + ":" +
System.DateTime.Now.Millisecond.ToString() - Msg = head + System.Environment.
NewLine + Msg + System.Environment.NewLine - Dim strDate As String
- strDate = System.DateTime.Now.
ToString("yyyyMMdd") - Dim strFile As String
- strFile = varAppPath + "\" +
strDate + ".log" - Dim SW As System.IO.StreamWriter
- SW = New System.IO.StreamWriter
(strFile, True) - SW.WriteLine(Msg)
- SW.Flush()
- SW.Close()
- End Sub
VB.NET寫(xiě)Log方法相關(guān)代碼編寫(xiě)方法就為大家介紹到這里。
責(zé)任編輯:曹凱
來(lái)源:
博客園


















