Skip to content

Instantly share code, notes, and snippets.

@lockworld
Last active June 23, 2017 18:03
Show Gist options
  • Save lockworld/7b1ecc49dead348d42f98398c05aa7e1 to your computer and use it in GitHub Desktop.
Save lockworld/7b1ecc49dead348d42f98398c05aa7e1 to your computer and use it in GitHub Desktop.
Text formatting in C#
//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));
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