Public Sub log(ByVal mensaje As String)
Dim filename As String = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) & "\" & "log.txt"
If File.Exists(filename) Then
Dim archivo_size As Long = New FileInfo(filename).Length / 1024
If archivo_size >= 500 Then
Try
Kill(filename)
Catch ex As Exception
End Try
End If
End If
Dim tempfile As String = Path.GetTempFileName()
If Not File.Exists(filename) Then
File.Create(filename).Close()
End If
Using writer = New StreamWriter(tempfile)
Using reader = New StreamReader(filename)
writer.WriteLine("[" & Now.ToString("dd-MM-yyyy_HH:mm:ss") & "]-->" & mensaje)
While Not reader.EndOfStream
writer.WriteLine(reader.ReadLine())
End While
End Using
End Using
File.Copy(tempfile, filename, True)
File.Delete(tempfile)
End Sub
fuente1
No hay comentarios.:
Publicar un comentario