add Environment.NewLine at the end of each line
txtDiagnostic.Text += (DateTime.Now.ToString("hh:mm:ss:fff") + " " + message) + Environment.NewLine;
and make sure the text box is capable of multi-line
XAML:
<TextBox Name="tbMultiLine" TextWrapping="Wrap" AcceptsReturn="True" <-- IMPORTANT VerticalScrollBarVisibility="Visible" <-- IMPORTANT >
EDIT: to answer a normal discussion of a discussion of a string sequence, you can of course use string.Concat ()
String.Concat(txtDiagnostic.Text,DateTime.Now.ToString("hh:mm:ss:fff") , " " , "ERROR....." , Environment.NewLine);
It will be faster. Here is the reference code for LINQPad with 1000 lines:
void Main() { Stopwatch sw = new Stopwatch(); string text = ""; sw.Start(); for (int i = 0; i < 1000; i++) { //text += (DateTime.Now.ToString("hh:mm:ss:fff") + " " + "ERROR.....") + Environment.NewLine; String.Concat(text,DateTime.Now.ToString("hh:mm:ss:fff") , " " , "ERROR....." , Environment.NewLine); } sw.Stop(); Console.WriteLine("ELAPSED: " + sw.ElapsedMilliseconds); }
Output:
+ taken concatentation (on my machine) 16 msek
Concat 10 msek required
Choose yourself, you should know how many error messages you want to "tell" the user;)
Disclaimer: 1000 lines is a very bad indicator, but I chose it here to fit the option used. Reading more than 1000 (or even 1000) lines of error messages is not the software that I would like to use. If you start concatenating larger sets of strings (x> 1000), you really should use StringBuilder , as is also mentioned in the string concatenation topic discussed in the discussion section.