Log the warning messages in a text file from a cake script

假装没事ソ 提交于 2019-12-10 15:13:46

问题


I'm using the below cake script to compile my C# project. There are few warning messages shown in PowerShell while executing the script. I like to log the warnings in a text file which is in a physical location(ex: D:\WarningReport.txt). The below is the cake script task I use to compile the project.

Task("Build")
    .Does(() =>
{
    if(IsRunningOnWindows())
    {
      MSBuild("./src/Example.sln", settings =>
        settings.SetConfiguration(configuration));
    }
});

I like to add something like below,

LogWarningMessagesTo("D:\WarningReportes.txt");
LogErrorMessagesTo("D:\ErrorReportes.txt");

How to do this?


回答1:


If it's warnings and errors from MSBuild alias you want to log that's certainly possible using the AddFileLogger extension method on the MSBuildSettings parameter.

Basically change

  MSBuild("./src/Example.sln", settings =>
    settings.SetConfiguration(configuration));

to

MSBuild("./src/Example.sln", settings =>
    settings.SetConfiguration(configuration)
            .AddFileLogger(new MSBuildFileLogger {
                LogFile ="D:/WarningReportes.txt",
                MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.WarningsOnly })
            .AddFileLogger(new MSBuildFileLogger {
                LogFile ="D:/ErrorReportes.txt",
                MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.ErrorsOnly })
  );


来源:https://stackoverflow.com/questions/42271823/log-the-warning-messages-in-a-text-file-from-a-cake-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!