I wanted to add a timestamp to the writing file and tried this:
TextWriter iterationLogger = new StreamWriter($"{DateTime.Now} Iteration log.txt");
Then StremWritter throws exception The filename, directory name, or volume label syntax is incorrect
I tried various arguments (append, encoding, @, $) and formats, e.g. string.Format("{0} Iteration log.txt", DateTime.Now)
but the problem is still there.
As far as I understood, with just a string StreamWritter creates the file right inside the program folder, but something changed with the addition of DateTime inside the string that prevents file creation?
Update 16/03/2023
For any future reader - please check this reference: https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings