none
Custom Activity --- Write to the log file.

    Question

  • I have a custom activity. Now I want to write some information into the log file. How can I do that? I am using code activity not xaml. Thanks.

    Jason Luo

    Thursday, May 06, 2010 8:30 PM

Answers

  • Thh build.log is generated by MSBuild while compiling the projects in your solution(s). This information is only related to the compilation. There is no log file generated for the build workflow itself, there is only the build log view.

    If you have legacy builds from earlier versions of TFS, and using the UpgradeTemplate to build them, then the MSbuild log file actually contains the whole build process, since MSBuild is still used to execute the TFSBuild.proj file beneath the surface

    Regards
    /Jakob


    Blog: http://geekswithblogs.net/jakob Twitter: http://twitter.com/osirisjakob
    • Marked as answer by jason Luo Monday, May 10, 2010 3:04 PM
    • Unmarked as answer by jason Luo Tuesday, May 11, 2010 2:34 PM
    • Marked as answer by jason Luo Tuesday, May 11, 2010 2:34 PM
    Monday, May 10, 2010 2:40 PM
  • That particular log file is generated by our logger, which is only used when you invoke the TfsBuild activity in the upgrade template. It will also be attached when you use the MSBuild activity from our activity library, but this logger is slightly different as it is geared toward our workflow process.

    To answer you question in more detail, the log you refer to is specific to MSBuild. The "build log" that you see in visual studio, which is also what we have been referring to in this post with respect to BuildMessage, is how we track detailed information about your build workflow in the server.

    If you would like to create a log file then you should probably create it yourself using the WriteLine activity from the WF 4.0 framework, providing your own TextWriter that writes to a file.

    Patrick

    • Marked as answer by jason Luo Monday, May 10, 2010 3:04 PM
    • Unmarked as answer by jason Luo Tuesday, May 11, 2010 2:33 PM
    • Marked as answer by jason Luo Tuesday, May 11, 2010 2:34 PM
    Monday, May 10, 2010 2:47 PM

All replies

  • Hi Jason, try this:

            protected void TrackMessage(CodeActivityContext context, string message, BuildMessageImportance importance)

            {

                context.Track(

                    new BuildInformationRecord<BuildMessage>()

                    {

                        Value = new BuildMessage() { Importance = importance, Message = message }

                    });

            }        

     

    Call this method with the context from your custom activity and the message and importance.

    Regards
    /Jakob


    Blog: http://geekswithblogs.net/jakob Twitter: http://twitter.com/osirisjakob
    • Proposed as answer by Todd Beaulieu Tuesday, August 16, 2011 2:42 PM
    Thursday, May 06, 2010 9:40 PM
  • Hi Jakob,

    Which assembly defines BuildInformationRecord? I search BuildInformationRecord in all Microsoft.TeamFoundation.*, I can't find it. Can you please provide me with the namespace and assembly? Thanks.

     

    Jason

    Friday, May 07, 2010 5:30 PM
  • It looks to me that context.Track takes

    System.Activities.Tracking.

     

    CustomTrackingRecord.

    I am still using RC version. Is the final version different? Thanks.

    Friday, May 07, 2010 5:35 PM
  • Hi Jason, sorry for the late reply.

    Actually, the BuildInforamtionRecord class is located in the Microsoft.TeamFoundation.Build.Workflow.Tracking namespace. You'll need to reference the Microsoft.TeamFoundation.Build.Workflow assembly located in %program files x86%\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\

    And, my sample code actually references an internal class of mine (BuildMessage), sorry for that. This class is just simple data container:

    public sealed class BuildMessage 
    { 
      public String Message { get; set; } 
      public BuildMessageImportance Importance { get; set; } 
    }

     ANother thing: Make sure that you pass in BuildMessageImportance.High when you write a message to the log, otherwise it won't be visible in a build that uses the default verbosity (normal)

    Hope that helps
    /Jakob


    Blog: http://geekswithblogs.net/jakob Twitter: http://twitter.com/osirisjakob
    Monday, May 10, 2010 2:05 PM
  • Microsoft.TeamFoundation.Build.Workflow.Tracking.BuildInformationRecord is a subclass of CustomTrackingRecord, so this should not pose any issues.

    Patrick

    Monday, May 10, 2010 2:06 PM
  • Jakob,

    I just want to clarify my question. I want to write something to "Log file" not "Log". I think Log file should have everything no matter what verbosity is. Am I right? Thanks.

     

    Jason

    Monday, May 10, 2010 2:09 PM
  • Which "log file" are you referring to? A custom log file or the build.log file generated from our msbuild based process?

    Patrick

    Monday, May 10, 2010 2:16 PM
  • Patrick,

    The log file (*.log) in the droplocation. Currently I don't see a log file got generated in the droplocation, however, I see the acitivity log. I had another post for the question http://social.msdn.microsoft.com/Forums/en/tfsbuild/thread/43dbb923-5944-4db9-8aab-2bd5bde761da. Thanks.

     

    Jason

    Monday, May 10, 2010 2:28 PM
  • How does build.log different from acitivity log? Does build.log has all information in activity log PLUS some other detail information? Thanks.

     

    Jason

    Monday, May 10, 2010 2:30 PM
  • Thh build.log is generated by MSBuild while compiling the projects in your solution(s). This information is only related to the compilation. There is no log file generated for the build workflow itself, there is only the build log view.

    If you have legacy builds from earlier versions of TFS, and using the UpgradeTemplate to build them, then the MSbuild log file actually contains the whole build process, since MSBuild is still used to execute the TFSBuild.proj file beneath the surface

    Regards
    /Jakob


    Blog: http://geekswithblogs.net/jakob Twitter: http://twitter.com/osirisjakob
    • Marked as answer by jason Luo Monday, May 10, 2010 3:04 PM
    • Unmarked as answer by jason Luo Tuesday, May 11, 2010 2:34 PM
    • Marked as answer by jason Luo Tuesday, May 11, 2010 2:34 PM
    Monday, May 10, 2010 2:40 PM
  • That particular log file is generated by our logger, which is only used when you invoke the TfsBuild activity in the upgrade template. It will also be attached when you use the MSBuild activity from our activity library, but this logger is slightly different as it is geared toward our workflow process.

    To answer you question in more detail, the log you refer to is specific to MSBuild. The "build log" that you see in visual studio, which is also what we have been referring to in this post with respect to BuildMessage, is how we track detailed information about your build workflow in the server.

    If you would like to create a log file then you should probably create it yourself using the WriteLine activity from the WF 4.0 framework, providing your own TextWriter that writes to a file.

    Patrick

    • Marked as answer by jason Luo Monday, May 10, 2010 3:04 PM
    • Unmarked as answer by jason Luo Tuesday, May 11, 2010 2:33 PM
    • Marked as answer by jason Luo Tuesday, May 11, 2010 2:34 PM
    Monday, May 10, 2010 2:47 PM
  • Thanks all!
    Monday, May 10, 2010 3:04 PM
  • Hi,

    Thank you everyone for your enthusiastic and friendly help!

    Best Regards,

    Cathy Kong

    Tuesday, May 11, 2010 1:56 AM
    Moderator
  • I know this is an old thread but since there is a much easier way to do this now (might have been introduced after this thread was answered), anyway, in case others are interested:

    Simply use the TrackBuildMessage in the CodeActivityContext (System.Activities.CodeActivity) passed into the Execute method of your Code Activity like so:

    context.TrackBuildMessage("Hello world");

    There's also an overload that lets you specify the BuildMessageImportance...

    • Proposed as answer by GMelencio Wednesday, September 28, 2011 4:50 PM
    Wednesday, September 28, 2011 4:50 PM
  • Simply use the TrackBuildMessage in the CodeActivityContext (System.Activities.CodeActivity) 

     Which is an extension in namespace Microsoft.TeamFoundation.Build.Workflow.Activities ... just to be complete :)

    Friday, January 25, 2013 1:22 PM