Code cutting off string after runs many times

c#, streamwriter, string, text-files

Solution

Make sure you have flushed your `outfile` buffer.

Problem

This code runs in a loop. After the 38th time it runs, the string that gets printed to the text file cuts off immediately after the second "M", doesn't even print the comma, and then stops printing everything and ends. What could be the cause of this? ``` private static void LogPayment(CDefeasancePayment paymentToLog, System.IO.StreamWriter outfile) { string line = "AddDefeasancePayment(DateTime.Parse(\"" + paymentToLog.PaymentDate.ToShortDateString() + "\"), " + paymentToLog.Interest + "M, " + paymentToLog.Principal + "M, DateTime.Parse(\"" + paymentToLog.StripDate.ToShortDateString() + "\"), " + paymentToLog.StripPrice + "M);\n"; outfile.Write(line); } ```

Original source