如果我们想使用VB.NET进行代码编写的话,首先就要从基本概念开始了解,然后通过不断的实践练习来积累一定的运用经验,才能很好的通过这款语言来实现我们需要的各种需求。下面就先来了解一下有关VB.NET写Log方法的相关操作。#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方法相关代码编写方法就为大家介绍到这里。