Last active
June 23, 2017 18:03
-
-
Save lockworld/7b1ecc49dead348d42f98398c05aa7e1 to your computer and use it in GitHub Desktop.
Text formatting in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Ref: https://stackoverflow.com/a/2866650 | |
var timestamp = DateTime.Now.ToString("yyyy'-'MM'-'dd hh':'mm':'ss.fff"); | |
var msgType = "INFORMATION"; | |
var msgText = "This is an example of how to format a text string to align fragments on a line, like a typical log file."; | |
LogFile.Write(string.Format("{0,-25} {1,-15} {2}", timestamp, msgType, msgText)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2017-06-19 08:16:49.518 INFORMATION This is an example of how to format a text string to align fragments on a line, like a typical log file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment