How to: Open and Append to a Log File
StreamWriter and StreamReader write characters to and read characters from streams. The following code example opens the log.txt file for input, or creates the file if it does not already exist, and appends information to the end of the file. The contents of the file are then written to standard output for display. As an alternative to this example, the information could be stored as a single string or string array, and the WriteAllText or WriteAllLines method could be used to achieve the same functionality.
Note |
|---|
| Visual Basic users may choose to use the methods and properties provided by the My.Application.Log or My.Computer.FileSystem objects for creating or writing to log files. For more information, see My.Application.Log Object and My.Computer.FileSystem Object. |
Example
See Also
Tasks
How to: Create a Directory ListingHow to: Read and Write to a Newly Created Data File
How to: Read Text from a File
How to: Write Text to a File
How to: Read Characters from a String
How to: Write Characters to a String
Reference
StreamWriterStreamReader
File.AppendText
File.OpenText
StreamReader.ReadLine
Note