Avatar of Prysson
Prysson

asked on 

Help with StreamWriter newline

I am trying to write a class that write a log based on a fairly long routing.

At various instances in the routine I need to pass the logfile name and the string I need written into a method and have it basically start a new line and add the string to the log.txt file.

this is what I have for my method

public static bool WriteLogFile(string filename, string line)
        {
             bool b = false;

             try
             {
                 using (StreamWriter sw = new StreamWriter(filename))
                 {
                     // Add some text to the file.                    
                     sw.WriteLine(line);
                     sw.Close();
                     

                 }
                 b = true;

             }
             finally
             {
             }
             return b;
        }

So my problem is that this code just keeps overwriting the first line of the log file...anyone know how I can modify this code so it will create a new line and add the string their?

C#

Avatar of undefined
Last Comment
abel

8/22/2022 - Mon