Para crear archivos de Logs primero vamos a utilizar las siguientes librerias:
1 2 |
Imports System Imports System.IO |
Ahora utilizaremos la siguiente funcion:
1 2 3 4 5 6 7 8 |
Public LogFile As String = "\" + DateTime.Now.ToString("dd-MM-yyyy") + "-" + DateTime.Now.ToString("hhmmss") + ".log" Private Function SysLog(TextLogP As String) Using outputFile As New StreamWriter(Application.StartupPath & Convert.ToString(LogFile), True) outputFile.WriteLine(DateTime.Now.ToString("dd/MM/yyyy") + " " + DateTime.Now.ToString("hh:mm:ss") + " - " + TextLogP) End Using Return False End Function |
La misma lo que hace es crear un archivo nuevo con el nombre prediceñado en LogFile y escribirlo con los detalles del mensaje, se utiliza de la siguiente manera:
1 |
SysLog("Info: Inicio del Programa.") |
Ejemplo al iniciar el programa:
1 2 3 4 5 6 |
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load SysLog("Inicio del programa.") SysLog("Archivo de Log Creado.") End Sub |