Beautifully formatted text file

I am writing to a text file and it looks like this ...

19/05/2010 15:33:34 Verbose Main in main method 19/05/2010 15:33:34 Information DoesSomethingInteresting() the answer to faster than light travel is 

But what identifier should look like this:

 19/05/2010 15:33:34 Verbose Main in main method 19/05/2010 15:33:34 Information DoesSomethingInteresting() the answer to faster than light travel is 

You know, so everything is nicely formatted and tabbed aligned. Is there an easy way to do this, some runtime functions that will handle all the tedious add-ons?

Here is my code that records

 LogFile.Write(string.Format("{0}\t{1}\t{2}\t{3}", log.Time, log.Level, log.Method, log.Message)); 
+3
source share
1 answer

To align the string to the left, use the formatting pattern with a comma (,) followed by a negative number of characters:

 LogFile.Write(string.Format("{0,-10} {1,-11} {2,-30} {3}", ...)); 

For proper alignment, use a positive number.

+9
source

Source: https://habr.com/ru/post/917039/


All Articles