格式很好的文本文件

Rob*_*Rob 3 c# asp.net

我正在写一个文本文件,它看起来像这样......

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
Run Code Online (Sandbox Code Playgroud)

但我希望它看起来像是......

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
Run Code Online (Sandbox Code Playgroud)

你知道,所以它的格式和标签对齐都很好.有没有一种简单的方法可以做到这一点,运行时的某些功能将处理所有繁琐的填充?

这是我编写的代码

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

dtb*_*dtb 13

要将字符串与左对齐,请使用逗号(,)后跟负数字符的格式化模式:

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

对于右对齐,请使用正数.