• Welcome to Valhalla Legends Archive.
 

[VB.NET] Log time with milliseconds

Started by Smurfling, December 17, 2003, 03:42 AM

Previous topic - Next topic

Smurfling

Well for those who are interested:

Grok's WriteLog in VB .NET


Imports System
Imports System.IO


   Public Sub WriteLog(ByVal Text As String)
       Try
           Dim FileHolder As FileInfo _
           = New FileInfo(Date.Now.Year & Date.Now.Month & Date.Now.Day & ".txt")
           Text = Text.Insert(0, "[" & Format(Date.Now.Hour, "00") _
           & ":" & Format(Date.Now.Minute, "00") _
           & ":" & Format(Date.Now.Second, "00") _
           & ":" & Format(Date.Now.Millisecond, "0000") & "]  ")
           If FileHolder.Exists Then
               Dim WriteFile As StreamWriter = FileHolder.AppendText()
               WriteFile.WriteLine(Text)
               WriteFile.Close()
           Else
               Dim WriteFile As StreamWriter = FileHolder.CreateText()
               WriteFile.WriteLine(Text)
               WriteFile.Close()
           End If
       Catch ex As Exception
           MsgBox(ex.ToString)
       End Try
   End Sub


Usage - not that hard ;)

WriteLog("Well i really want to log now something :-)")