简体   繁体   中英

Nicely formatted text file

I'm 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 i'd like it to look like is...

 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 it's all nicely formatted and tabbed aligned. Is there an easy way to do this, some function in the runtime that will deal with all the tedious padding?

Here is my code that does the writing

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

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

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

For right alignment use a positive number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM