Search code examples
c#stringcolorstextcolor

How can I paint a string in text file using C#?


My program is generating a log, adding strings line by line. Final output (log file) is ending with .txt extension.

There are 3 types of lines: ERROR, WARNING and INFO.

I want to make the ERROR lines to be red, WARNING lines to be yellow, and INFO lines to be green. I'm working in C# and I am using Visual Studio Code.

How could I possibly do that kind of coloring?

NOTE: If I have to change the format of log file (not to be .txt anymore), I am okay with that.

Thanks a lot!


Solution

  • You can't put color in text file. If you have to, you could log into html and use the possibilities of html & css for coloring and formatting.
    see Simple text to HTML conversion.