Logger Learn programming Visual Basic (VB.net)


File Management




Create a class Logger, with a static method Write, which will append a certain text to a file: Logger.Write("myLog.txt", "This text is being logged");

It must also include the current date and time before the text (in the same line), so that the log file is easier to analyze.

Hint: find information about "AppendText" and about "DateTime.now"


Imports System
Imports System.IO
Namespace LoggerAplication
    Class Logger
        Public Shared Sub Write(ByVal nameFile As String, ByVal text As String)
            Dim myFile As StreamWriter
            myFile = File.AppendText(nameFile)
            myFile.WriteLine(DateTime.Now & " - " & text)
        End Sub
    End Class
End Namespace

Namespace LoggerAplication
    Class Program
        Private Shared Sub Main()
            Logger.Write("text.txt", "Hola")
        End Sub
    End Class
End Namespace

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.