I am using an error log function which writes exceptions in a ~/App_Data/ErrorLog.txt file in the following format-
Created on: .... + Environment.NewLine
Error Description: .... + Environment.NewLine
Source File: .... + Environment.NewLine
Method: .... + Environment.NewLine
Line: .... + Environment.NewLine
Column: .... + Environment.NewLine
________________________________________________________________________
Now i am viewing it in browser. But NewLine character disappeared. I used System.IO.StreamReader
to read the texts.
How can i keep the html as the above format?
Or, Is there any way to open the .txt file directly in browser from App_Data directory?
Thank you.
asked Dec 21, 2014 at 5:19
1 Answer 1
when you want to put it on the page replace \n
with <br />
:
StringBuilder sb = new StringBuilder();
sb.Append("This is a test" + "\n");
sb.Append("This is a test" + "\n");
sb.Append("This is a test" + "\n");
var result = sb.ToString().Replace("\n", "<br />");
// put result on the page
// note: StringBuilder works like StreamReader when you call StreamReader.ReadToEnd().Replace("\n", "<br />");
answered Dec 21, 2014 at 5:23
-
Thanks Mohamad. It works. But @Html.Raw(ViewBag.ErrorLogs) is needed to render it on razor view page. Anyway, +1.s.k.paul– s.k.paul2014年12月21日 05:36:42 +00:00Commented Dec 21, 2014 at 5:36
-
Far better to just use css (
whitespace: pre;
)user3559349– user35593492014年12月21日 05:53:17 +00:00Commented Dec 21, 2014 at 5:53
lang-cs