[英]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.
最终输出(日志文件)以.txt扩展名结尾。
There are 3 types of lines: ERROR , WARNING and INFO . 有3种类型的行: ERROR , WARNING和INFO 。
I want to make the ERROR lines to be red, WARNING lines to be yellow, and INFO lines to be green. 我想将ERROR行设为红色,将WARNING行设为黄色,将INFO行设为绿色。 I'm working in C# and I am using Visual Studio Code.
我正在使用C#,并且正在使用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. 注意:如果我必须更改日志文件的格式(不再是.txt),则可以。
Thanks a lot! 非常感谢!
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.
如果需要,您可以登录html并使用html&css进行着色和格式化的可能性。
see Simple text to HTML conversion . 请参阅从简单文本到HTML的转换 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.