|
-
December 5th, 2008, 07:33 AM
#1
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
-
December 5th, 2008, 07:56 AM
#2
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
-
December 5th, 2008, 08:11 AM
#3
Re: create Log file
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010
-
December 5th, 2008, 10:14 AM
#4
Re: log file
As a VB6 user in the VB6 forum I'd answer
Code:
Open Filename For Append as #1
But since you asked for VB.NET, the answer is different.
If you opened your file as a StreamWriter you'd have to use
Code:
myStreamWriter = File.AppendText(txtFileName.Text)
More detailed answers you'd certainly get faster in the VB.NET forum.
-
December 5th, 2008, 10:42 AM
#5
Re: log file
 Originally Posted by kku
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
Use the streamwriter method and set append = true
Code:
Dim file As New System.IO.StreamWriter("\LogFile.txt", True)
file.WriteLine(logtext)
file.Close()
The variable logtext of course should have the text you want to log prior to the above code.
-
December 9th, 2008, 08:50 AM
#6
Re: log file
 Originally Posted by kku
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
Each time you generate a new log line, store it on an arraylist, like YourArrayList
Each time you want it to be saved, use
Code:
Dim fs As FileStream = File.Open(LogFilePath, FileMode.OpenOrCreate)
Dim sr As New StreamWriter(fs)
sr.Write(String.Join(vbCrLf, YourArrayList))
sr.Close()
[Vb.NET 2008 (ex Express)]
-
December 9th, 2008, 10:29 PM
#7
Re: log file
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...
-
December 10th, 2008, 07:55 AM
#8
Re: log file
 Originally Posted by dglienna
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...
You are right. Maybe it should .clear the arraylist after saving.
[Vb.NET 2008 (ex Express)]
-
December 10th, 2008, 09:01 AM
#9
Re: log file
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.
Last edited by TheCPUWizard; December 10th, 2008 at 09:36 AM.
Reason: Fixed spelling error.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|