因为我没有任何带有IIS的Windows服务器,我可以在其上测试应用程序的功能,我想问下面的代码是否会按照我的预期方式运行 - 网络应用程序向控制台写入内容,我需要将控制台中写入的内容保存到特定文件中。我正在使用Visual Studio 2013安装的ISS Express在我的笔记本电脑上进行本地测试。
IIS Express是否与Windows Server上的IIS相同,所以我可以在下面使用这段代码?
using (var consoleWriter = new StreamWriter(
new FileStream(_tempOutputFileName,
FileMode.Create, FileAccess.Write)))
{
Console.SetOut(consoleWriter);
//do some work here with output to console
}
var standardOutput =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
Console.SetOut(standardOutput);
编辑:我无法直接写入文件,因为我需要抓住我正在使用的第三方库写入控制台的内容。