Write to the ActivityLog

This sample demonstrates how to use the ActivityLog class of the VSXtra framework.
Visual Studio can be started in activity logging mode with the /log command line switch. In this mode VSPackage messages written to the VS Activity Log are recorded into an XML file that later can be displayed and used for testing, checking, troubleshooting, etc. When you start your Visual Studio session without the /log command, messages sent to the activity log will not be saved to the log file.
Anytime you start a new /log VS session the previous activity log file is overridden. This file is called ActivityLog.Xml and its location is within your user profile folder under the Microsoft\VisualStudio\<Hive>\UserSettings folder. The <Hive> parameter is determined by the version of Visual Studio you run (it is 9.0 for VS 2008) and the /rootsuffix command line switch that is Exp for the Experimental hive. So, when you develop packages with VS 2008 SDK, <Hive> usually has the value of 9.0Exp. Do not forget that your root user profile folder is determined by a lot of factors (your login name, profile type, OS, etc.).
For example, if your login name is jsmith and you have a roaming profile on Windows Vista, you may find the activity log under the following folder: C:\Users\jsmith\AppData\Roaming\Microsoft\VisualStudio\9.0Exp\UserSettings

Package source code:

using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using VSXtra;

namespace DeepDiver.ActivityLogPackage
  [PackageRegistration(UseManagedResourcesOnly = true)]
  [InstalledProductRegistration(false, "#110", "#112", "1.0", IconResourceID = 400)]
  [ProvideLoadKey("Standard", "1.0", "ActivityLog", "DeepDiver", 1)]
  [ProvideMenuResource(1000, 1)]
  public sealed class ActivityLogPackage : PackageBase
    protected override void Initialize()
      ActivityLog.Write(GetType().Name, "Package initialized.");

    protected override void Dispose(bool disposing)
      ActivityLog.Write(GetType().Name, "Package is being disposed.");

    [CommandId(GuidList.guidActivityLogCmdSetString, CmdIDs.cmdidWriteEntry)]
    [ShowMessageAction("An entry is being written to the Activity Log.")]
    private void WriteEntry()
      ActivityLog.Write(GetType().Name, "WriteEntry method called.");

Last edited Aug 9, 2008 at 8:03 AM by INovak, version 2


No comments yet.