Hack Forums
[.NET] [VB.NET]Adding Log File - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [VB.NET]Adding Log File (/showthread.php?tid=394148)



[VB.NET]Adding Log File - codepoet - Apr 30, 2010

Code
Sub Log(ByVal txt As String)
'Open a file for writing
Dim FILENAME As String = Server.MapPath("Log.txt")

Get a StreamReader class that can be used to read the file

Dim objStreamWriter As StreamWriter

objStreamWriter = File.AppendText(FILENAME)

objStreamWriter.WriteLine(DateTime.Now.ToString() + " >> " + txt)

'Close the stream

objStreamWriter.Close()

End Sub


Rewritten by me from VB6


If You Like this tutorial,
please check out my other tutorials by clicking ==> here



* - Stylis - Apr 30, 2010

Little amelioration

Code
Private Function Log(ByVal sFile As String, ByVal sText As String)
    Dim objStreamWriter As System.IO.StreamWriter

    objStreamWriter = System.IO.File.AppendText(Application.StartupPath & "\" + sFile)
    objStreamWriter.WriteLine(DateTime.Now.ToString() + " >> " + sText)
    objStreamWriter.Close()

    Return Nothing
End Function

Example:

Code
Log("logs.txt", "Application started !")

Very good snippet !


* - Mark Webber's B1tch - Apr 30, 2010

Nice man..

Excellent for people that likes to make their applications a bit more special.

Thanks for sharing mate.


* - codepoet - Apr 30, 2010

you are very welcome...


2short


* - codepoet - Apr 30, 2010

If You Like this tutorial,
please check out my other tutorials by clicking ==> here