且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从控制台输出中记录特定行?

更新时间:2023-12-06 17:03:16

if (value > 25)
{
    File.AppendAllText("logfile.log", "[" + DateTime.Now.ToString() "] " + value.ToString());
}





这是一种简单的方法......



如果要将输出重定向到文件,可以使用:



Console.SetOut [ ^ ]



但你不能同时拥有控制台窗口和文件在同一时间。



That's the simple way of doing it...

If you want to redirect the output to a file, you can use:

Console.SetOut[^]

But you can't have it both the console window and the file at the same time.