I figured out this way to implement a log file for an application by using an xml file and adding it to the final compliation.
In the solution add a new xml file.
In the properties of that file, there are 2 things to set, the build action and the copy to output direcotry.
Make sure the build action is Content
Make sure the Copy to Output Directory is Copy if newer
The settings for the "copy to output directory" are "Do not copy", "Copy Always" and "Copy if Newer"
The do not copy option doesn't put a file into the final build directory, and if this is selected, a relative reference to the file cannot be obtained. The copy always option copies the file as it exists to the build directory for every build, and therefore will delete any changes you made programmatically. This is not desirable when you are testing. The copy if newer allows for only copying the file over if the original file has changed and therefore has a newer timestamp.
These settings ensure that the file is copied to the bin/debug folder on a build. Then one can reference the xml file in a relative manner so the path need not be known.
Here is an example of a routine to open a log file and append an entry.
Public Shared Sub AddEntryToLog()
Dim xmlDoc As New System.Xml.XmlDocument()
xmlDoc.Load("Logs.xml")
Dim objElement As Xml.XmlElement = xmlDoc.CreateElement("entry")
objElement.InnerText = "Added a log entry."
objElement.SetAttribute("date", "4/2/2008")
xmlDoc.SelectSingleNode("logs").AppendChild(objElement)
xmlDoc.Save("Logs.xml")
End Sub
Here is the log file with the entry from above.
<?xml version="1.0" encoding="utf-8"?>
<!-- Logs of reminders sent.-->
<logs>
<entry date="4/2/2008">Added a log entry.</entry>
</logs>