VB.NET寫Log方法詳細(xì)介紹
作者:佚名
VB.NET寫Log方法的功能實現(xiàn),可以通過本文介紹的這樣一段代碼來實現(xiàn)。我們可以通過對這段代碼的解讀,詳細(xì)掌握其中的編寫技巧。
如果我們想使用VB.NET進(jìn)行代碼編寫的話,首先就要從基本概念開始了解,然后通過不斷的實踐練習(xí)來積累一定的運(yùn)用經(jīng)驗,才能很好的通過這款語言來實現(xiàn)我們需要的各種需求。下面就先來了解一下有關(guān)VB.NET寫Log方法的相關(guān)操作。#t#
最近在項目中有用到VB.NET寫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寫Log方法相關(guān)代碼編寫方法就為大家介紹到這里。
責(zé)任編輯:曹凱
來源:
博客園