Update
As Greg mentions in the comments below, MSBuild can write out to a log file while also outputting to console out of the box.
MSBuild [options] /filelogger /fileloggerparameters:LogFile=MSBuildLog.txt
Try the following simple C# program. It will take the redirected STDIN (Console.In
) and write it to one or more files and STDOUT (Console.Out
).
using System;
using System.Collections.Generic;
using System.IO;
namespace RedirectToFile
{
class Program
{
static void Main(string[] args)
{
var buffer = new char[100];
var outputs = new List<TextWriter>();
foreach (var file in args)
outputs.Add(new StreamWriter(file));
outputs.Add(Console.Out);
int bytesRead;
do
{
bytesRead = Console.In.ReadBlock(buffer, 0, buffer.Length);
outputs.ForEach(o => o.Write(buffer, 0, bytesRead));
} while (bytesRead == buffer.Length);
outputs.ForEach(o => o.Close());
}
}
}
I use it to redirect the output from an MSBuild batch file to disk whilst still outputting to the console window.
Usage: MSBuild [options] | RedirectToFile.exe MSBuildLog.txt