I created a class with the responsibility to generate a text file where each line represents the information of an object of \'MyDataClass\' class. Below is a simplification
I just now had a similar problem where the code below would randomly insert blank lines in the output file (outFile)
using (StreamWriter outFile = new StreamWriter(outFilePath, true)) {
foreach (string line in File.ReadLines(logPath)) {
string concatLine = parse(line, out bool shouldWrite);
if (shouldWrite) {
outFile.WriteLine(concatLine);
}
}
}
Using Antar's idea I changed my parse function so that it returned a line with Environment.NewLine appended, ie
return myStringBuilder.Append(Environment.NewLine).ToString();
and then in the foreach loop above, changed the
outFile.WriteLine(concatLine);
to
outFile.Write(concatLine);
and now it writes the file without a bunch of random new lines inserted. However, I still have absolutely no idea why I should have to do this.