Skip to sidebar Skip to content
Ipercube Technical
Jack of all trades, master of none
Date: Time: - Stardate:
Welcome, Log in by clicking  Here!
SS64
MDN
Stack
Code
GitHub
Wiki
Convert
V Studio
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions
Ipercube Technical
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions

Write Log

Writes a single line of text to a log file, optionally prefixed with a timestamp.

The function remembers the last specified log file path across calls. Special keywords (e.g., JustRememberTheLogFileName ) are ignored. Any carriage return or line feed characters in the log line are removed to ensure clean log formatting.

VB
    Public Sub WriteLog(Line As String, 
                        Optional LogFileName As String = "", 
                        Optional AddTimeStamp As Boolean = True)

        Static SaveLogFileName As String

        If Not String.IsNullOrEmpty(LogFileName) Then
            If SaveLogFileName <> LogFileName Then SaveLogFileName = LogFileName
        End If

        If Line = JustRememberTheLogFileName Then Return

        'Write line
        If Not String.IsNullOrEmpty(Line) Then
            Try
                Dim szMessage As String = Line.Replace(vbCr, " ").Replace(vbLf, "")
                If AddTimeStamp Then szMessage = Now & "   " + szMessage
                File.AppendAllText(SaveLogFileName, szMessage & Environment.NewLine)
                Console.WriteLine(szMessage)
            Catch ex As Exception
            End Try
        End If

    End Sub

Posted by ipercube


© 2026 Ipercube Design