hi experts,
i am going to create a log file in vb.net...
when i write a text file its overwrite previous text..so how can i append text
or any sugestion about create log file
Printable View
hi experts,
i am going to create a log file in vb.net...
when i write a text file its overwrite previous text..so how can i append text
or any sugestion about create log file
hi experts,
i am going to create a log file in vb.net...
when i write a text file its overwrite previous text..so how can i append text
or any sugestion about create log file
Theres a nice example here:
http://www.codeproject.com/KB/vb/Err...tsExample.aspx
As a VB6 user in the VB6 forum I'd answer
But since you asked for VB.NET, the answer is different.Code:Open Filename For Append as #1
If you opened your file as a StreamWriter you'd have to use
More detailed answers you'd certainly get faster in the VB.NET forum. :)Code:myStreamWriter = File.AppendText(txtFileName.Text)
Each time you generate a new log line, store it on an arraylist, like YourArrayList
Each time you want it to be saved, useCode:Dim fs As FileStream = File.Open(LogFilePath, FileMode.OpenOrCreate)
Dim sr As New StreamWriter(fs)
sr.Write(String.Join(vbCrLf, YourArrayList))
sr.Close()
Not likely.
If you write the array again and again, it will append a NEW list to the end of the old list. Eventually, something will grow too big...Code:.OpenOrCreate
WHY reinvent the wheel. The Enterprise Library Logging block will meet you needs perfectly. No code to write, simply link it in, update your config and your are done (except for adding the logging calls at appropriate locations in your program).
btw: The same is true for DataAcces, ExceptionHandling, Advanced Configuration, Dependancy Injection, and a whole slew of other common tasks.
I have not written a (non-trivial non-throwaway) application without using EL in over 4 years. I have even updated all my VS project templates to automatically setup and configuration my projects upon creation.