Search This Blog

Wednesday, December 06, 2006

Custom Build Logger (ILogger)

Developers were complaining that the build log (Build.log) is too complicated to read and they only want so see the log when the build fails and why.

The first thing I though doing was to write a log reader. Wrong!!! I googled "team build logger" and found this page: which explains how to write a custom build logger (by implementing ILogger interface). I was already familiar with this interface and used it once while writing an MSBuild script executer. The important stuff from this blog was that you can register a custom logger for a team build by adding a line to the TFSBuild.rsp for the build type (/Logger:LoggerClassFullName, AssemblyFileName ).

So, I've implemented a new logger which captures build errors and send them at the end of the build to developers. The thing is that failed tests are treated as warning and do not fail the build (The log view in Visual Studio captures the warnings and mark the build as failed). The worse thing is that there is not logging regarding the failed tests. So we are back where we've started with a log that only says that the tests failed. The next step to try and solve this issue was finding the trx files and parsing them for the test results. In the code below you can see how I did it. Ignore the whole code just look at the SelectNodes and SelectSingleNode lines which retrieve the errors from the trx file. You can download the sources from here. Thank you Eyal for the free hosting... To make it work you need to update the config file with your settings and add the line: /Logger:BuildLoggers.ErrorsMailLogger, BuildLoggers.dll to the TFSBuild.rsp file.

XmlNodeList xmlNodeList = testResultsXmlDoc.SelectNodes("//UnitTestResult[errorInfo]");




No comments: