Reputation: 7291
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.
Upvotes: 0
Views: 792
Reputation: 8765
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 />");
Upvotes: 2