Search code examples
cakebuild

Cake Task output log to file


I have a set of Tasks inside a build.cake file and I would like to capture the log output from the console into a log file. I know it's possible to use the OnError() function to output errors to file but I would like to output everything to a log file, not just errors. Below is an example of the build.cake file.

#load "SomeTask.cake"
#load "SomeOtherTask.cake"

var target = Argument("target", "Default");

var someTask = Task("SomeTask")
.Does(() =>
{
     SomeMethodInsideSomeTask();
});

var someOtherTask = Task("SomeOtherTask")
.Does(() => 
{
    SomeOtherMethodInsideSomeOtherTask();
});

Task("Default")
.IsDependentOn(someTask)
.IsDependentOn(someOtherTask);

RunTarget(target);

N.B. The Tasks are not running any sort of MSBuild commands so it's not possible to use MSBuildFileLogger.


Solution

  • How about pipe the stdout to a file i.e.

    ./build.ps1 > log.txt