Logo

Programming-Idioms

  • C#

Idiom #145 Print log line with datetime

Print message msg, prepended by current date and time.

Explain what behavior is idiomatic: to stdout or stderr, and what the date format is.

Console.WriteLine($"[{DateTime.Now}] {msg}");

Default behavior of Console.WriteLine is stdout. DateTime should respect system culture defaults.
import std.experimental.logger;
log(msg);

the standard library package logger prints messages with their date and their call site.

New implementation...