Cake Task output log to file

2019-08-13 09:35发布

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.

标签: cakebuild
2条回答
再贱就再见
2楼-- · 2019-08-13 10:10

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

./build.ps1 > log.txt

查看更多
Root(大扎)
3楼-- · 2019-08-13 10:31

Have you heard about tee ? It reads standard input and writes it to both standard output and one or more files

查看更多
登录 后发表回答