开发者

Nicely formatted text file

开发者 https://www.devze.com 2022-12-31 13:05 出处:网络
I’m writing to a text file and it looks like this... 19/05/2010 15:33:34Verbose Mainin main method 19/05/2010 15:33:34Information DoesSomethingInteresting()the answer to faster than light travel is

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   Ver开发者_开发知识库bose     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.

0

精彩评论

暂无评论...
验证码 换一张
取 消