问题
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.
回答1:
How about pipe the stdout to a file i.e.
./build.ps1 > log.txt
回答2:
Have you heard about tee ? It reads standard input and writes it to both standard output and one or more files
来源:https://stackoverflow.com/questions/51073127/cake-task-output-log-to-file