VB.NET写Log方法详细介绍

开发 后端
VB.NET写Log方法的功能实现,可以通过本文介绍的这样一段代码来实现。我们可以通过对这段代码的解读,详细掌握其中的编写技巧。

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

最近在项目中有用到VB.NET写Log方法的功能.具体代码如下:

 

 

Code

  1. Public Sub WriteLog()Sub 
    WriteLog(ByVal Msg As String)  
  2. Dim varAppPath As String  
  3. varAppPath = System.AppDomain.
    CurrentDomain.SetupInformation.
    ApplicationBase + "log"  
  4. System.IO.Directory.CreateDirectory
    (varAppPath)  
  5. Dim head As String  
  6. head = System.DateTime.Now.Hour.
    ToString() + ":" + System.DateTime.
    Now.Minute.ToString()  
  7. headhead = head + ":" + System.DateTime.
    Now.Second.ToString() + ":" + 
    System.DateTime.Now.Millisecond.ToString()  
  8. Msg = head + System.Environment.
    NewLine + Msg + System.Environment.NewLine  
  9. Dim strDate As String  
  10. strDate = System.DateTime.Now.
    ToString("yyyyMMdd")  
  11. Dim strFile As String  
  12. strFile = varAppPath + "\" + 
    strDate + ".log"  
  13. Dim SW As System.IO.StreamWriter  
  14. SW = New System.IO.StreamWriter
    (strFile, True)  
  15. SW.WriteLine(Msg)  
  16. SW.Flush()  
  17. SW.Close()  
  18. End Sub 

VB.NET写Log方法相关代码编写方法就为大家介绍到这里。

责任编辑:曹凯 来源: 博客园
相关推荐

2009-11-10 12:42:47

VB.NET Prin

2009-10-28 09:55:29

VB.NET MyCl

2009-10-12 15:02:51

VB.NET动态控件

2010-01-21 16:45:00

VB.NET继承规则

2010-01-14 18:22:05

VB.NET硬盘速度测

2010-01-08 14:14:27

VB.NET使用Fin

2010-01-07 15:25:11

VB.NET数组

2010-01-22 10:41:33

VB.NET声明结构

2009-10-15 15:04:42

VB.NET PadL

2010-01-08 15:03:12

VB.NET类属性

2010-01-08 09:43:21

VB.NET汉字转换

2009-11-10 12:48:17

VB.NET三维模型

2010-01-15 19:17:23

2010-01-15 18:12:28

VB.NET超链接

2010-01-21 17:58:40

VB.NET List

2010-01-22 14:19:38

VB.NET调用jar

2010-01-07 16:51:56

VB.NET窗体钩子

2010-01-20 17:47:54

VB.NET注释

2010-01-19 18:37:24

VB.NET内存占用

2010-01-15 10:56:50

VB.NET继承实现多
点赞
收藏

51CTO技术栈公众号