How to break line using StreamWriter?

0

I have this code that generates a log whenever the service is finished, but it may happen that I have unprocessed NF and I need to list it for easy identification.

Example 100 NF were not processed. In this case you are listing everything on the same line instead of breaking.

publicvoidGerarLogoProcessamentoFim(){StreamWriterobjWR=newStreamWriter(processo,true);StringBuilderlinha=newStringBuilder();linha.Append("      --> NF PROCESSADAS: " + processadas);
        linha.Append("      --> NF NÃO PROCESSADAS: " + nprocessadas);
        if (nprocessadasNumero.Count > 0)
        {
            for (int i = 0; i < nprocessadasNumero.Count; i++)
            {
                linha.Append("NF - " + nprocessadasNumero[i]);
            }
        }
        linha.Append("      <-- FINALIZAÇÃO:" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"));
        objWR.WriteLine(linha.ToString());
        objWR.Close();
    }
    
asked by anonymous 26.06.2018 / 18:59

4 answers

1

Why do not you use

objWR.Write(string)

and

objWR.WriteLine(string)

instead of putting a row in a StringBuilder and printing, at the end of the loop, inside objWR ? In the end, it's in objWR you want output, so I used methods of that.

    
26.06.2018 / 19:25
1

Write, write without skipping line and WriteLine, write line and jump

objWR.WriteLine (string)

Or

These two below are equivalent, if you debug you will see that this Environment.NewLine is "/ r / n":

line.Append (Environment.NewLine); OR line.Append ("/ r / n");

    
28.09.2018 / 21:21
0

You can use:

linha.AppendLine();
    
26.06.2018 / 19:11
0
linha.Append(Environment.NewLine);
    
28.06.2018 / 16:15