In a previous post I dealt with the creation of a Custom Activity to use in TFS2010 builds, in that example I did not dealt about logging. Logging is a vital task to do in custom action, because it is quite difficult to attach a debugger to the Build Agent, and if a build fails, it is really important to be able to understand what is gone wrong.
If you want to log from a custom action you can use this simple function
private void LogMessage(String message, CodeActivityContext context) { BuildInformationRecord<BuildMessage> record = new BuildInformationRecord<BuildMessage>() { Value = new BuildMessage() { Importance = BuildMessageImportance.High, Message = message, }, }; context.Track(record); }
Thanks to this function I can use with my custom activity, here is how I use it in my XmlPoke activity, used to change content of an xml file.
LogMessage("XPoke on the file " + filePath, context);
Thanks to this message I can find information on the build log.
This is really useful because I can, in this example, verify witch file was changed by my action simply looking at the build log.
alk.
Tags: TfsBuild ContinuosIntegration
Tags: TfsBuild





