كود :
Public Sub addlog(ByVal s As String)
Dim path As String = (Application.StartupPath & "\Logs")
If Not Directory.Exists(path) Then
MkDir(path)
End If
Dim str2 As String = String.Format((path & "\{0}.txt"), DateTime.Today.ToString("dd-MMM-yyyy"))
Dim flag As Boolean = File.Exists(str2)
Using writer As StreamWriter = New StreamWriter(str2, True)
If Not flag Then
writer.WriteLine("Start Log for today")
End If
writer.WriteLine((Conversions.ToString(DateTime.Now) & " -- " & s))
End Using
Me.RichTextBox1.AppendText((s & ChrW(13) & ChrW(10)))
Me.RichTextBox1.ScrollToCaret()
Application.DoEvents()
If (Enumerable.Count(Of String)(Me.RichTextBox1.Lines) = &H1388) Then
Me.RichTextBox1.Clear()
End If
End Sub
Public Sub addlog(ByVal s As String, ByVal color As Color, ByVal isBold As Boolean, ByVal Optional newline As Boolean = False)
Dim box As RichTextBox = Me.RichTextBox1
If (newline AndAlso (box.TextLength > 0)) Then
box.AppendText(ChrW(13) & ChrW(10))
End If
box.SelectionStart = box.Text.Length
Dim selectionColor As Color = box.SelectionColor
box.SelectionColor = color
If isBold Then
box.SelectionFont = New Font(box.Font, FontStyle.Bold)
End If
box.AppendText( s)
box.SelectionColor = selectionColor
box.SelectionFont = New Font(box.Font, FontStyle.Regular)
box.ScrollToCaret()
box = Nothing
End Sub