public void EmptyErrorLogUsingWarningsErrorsOnly(string loggerOption) { using (var env = TestEnvironment.Create()) { var logFile = env.CreateFile(".log").Path; // Note: Only the ParallelConsoleLogger supports this scenario (log file empty on no error/warn). We // need to explicitly enable it here with the 'ENABLEMPLOGGING' flag. FileLogger fileLogger = new FileLogger { Parameters = $"{loggerOption};logfile={logFile};ENABLEMPLOGGING" }; Project project = ObjectModelHelpers.CreateInMemoryProject(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Target Name=`Build`> <Message Text=`Hello world from the FileLogger`/> </Target> </Project>"); project.Build(fileLogger); project.ProjectCollection.UnregisterAllLoggers(); // File should exist and be 0 length (no summary information, etc.) var result = new FileInfo(logFile); Assert.True(result.Exists); Assert.Equal(0, new FileInfo(logFile).Length); } }
public void LogVerbosityMessage(LoggerVerbosity loggerVerbosity, bool shouldContain) { using (var testEnvironment = TestEnvironment.Create()) { var fileLogger = new FileLogger { Verbosity = loggerVerbosity }; var logFile = testEnvironment.CreateFile(".log"); fileLogger.Parameters = "logfile=" + logFile.Path; Project project = ObjectModelHelpers.CreateInMemoryProject(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Target Name=`Build` /> </Project> "); project.Build(fileLogger); project.ProjectCollection.UnregisterAllLoggers(); string log = File.ReadAllText(logFile.Path); var message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("LogLoggerVerbosity", loggerVerbosity); if (shouldContain) { Assert.Contains(message, log); } else { Assert.DoesNotContain(message, log); } } }
public void Basic() { FileLogger fileLogger = new FileLogger(); string logFile = FileUtilities.GetTemporaryFile(); fileLogger.Parameters = "verbosity=Normal;logfile=" + logFile; Project project = ObjectModelHelpers.CreateInMemoryProject(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Target Name=`Build`> <Message Text=`Hello world from the FileLogger`/> </Target> </Project> "); project.Build(fileLogger); project.ProjectCollection.UnregisterAllLoggers(); string log = File.ReadAllText(logFile); Assert.Contains("Hello world from the FileLogger", log); // "Log should have contained message" File.Delete(logFile); }