I have a very small standalone vb.net application that starts automatically. From time to time, it gets into an error state, which I want to write down, and then continue processing. But this is too small a thing to store in the main log of the system - I just want to add a line to a text file.
What is the least stressful way to add a line of text to a file (and create a file if it's not there) in .net?
IO.File.AppendAllText (@ "Y: \ our \ File \ Name.here", "your log message is here")
VB.NET My.Computer.FileSystem.WriteAllText . My, System.IO.File.AppendAllText .
This is in C #, but for a change in VB it should be trivial:
void logMessage(string message) { string logFileName = "log.file"; File.AppendAllText(logFileName,message); }
Edited because Joel's solution was much simpler than my =)
Private Const LOG_FILE As String = "C:\Your\Log.file" Private Sub AppendMessageToLog(ByVal message As String) If Not File.Exists(LOG_FILE) Then File.Create(LOG_FILE) End If Using writer As StreamWriter = File.AppendText(LOG_FILE) writer.WriteLine(message) End Using End Sub
This MSDN article, How to Write Text to a File , Should Do It.
Source: https://habr.com/ru/post/1699297/More articles:How to convert a (short) sample to a sound file in an array of bytes - javaSaving static user data in a Windows C # application - c #Google docs download in bulk - google-docsЯвляется ли создание представления о неправильном стиле таблиц SharePoint? - sharepointMixing MFC and WPF: modal dialogs - wpfКаков наилучший способ разрешить как сервлет, так и клиентские скрипты читать один и тот же файл? - javaDesigning a Wiki, Design Considerations and Feedback - designPermission management recommendations? - securityC # 4.0 Feedback - c #Is this heart rate detection method thread safe and consistent? - javaAll Articles