This Guillaume Rouchon's post illustrates how to add a custom IntelliTraece event. Mine is to complement it with an enum type and updates in Visual Studio 2015 Update 2.
Let me summarize how to add a custom IntelliTrace event. The file you have to change is in a sub folder of Visual Studio installation folder, <VS installation folder>\Common7\IDE\CommonExtensions\Microsoft\IntelliTrace\14.0.0\en\collectionplan.xml. You need to have admin privilege to do that. This file only affect F5 debugging in Visual Studio. If you are using IntelliTrace standalone collector, you have to pass the collection plan file to the command line. So you can modify default one that comes with the standalone collector or write your own one.
What you need to do to add a custom event is
- Add a category under TracepointProvider/Categories
- Add an assembly under TracepointProvider/ModuleSpecifications
- Add your own diagnostic event specification under TracepointProvider/DiagnosticEventSpecifications
using System;
namespace ConsoleApplication1
{
enum Color
{
Red,
Green,
Blue
}
class Program
{
static void Main(string[] args)
{
PrintColor(Color.Blue);
}
static void PrintColor(Color color)
{
Console.WriteLine("Color: " + color);
}
}
}
Let's change the collection plan.
1. Add a new category.
<Category Id="enumSample" _locID="category.enumSample">Enum Sample</Category>
2. Add a new module
<ModuleSpecification Id="sample">ConsoleApplication1.exe</ModuleSpecification>
3. Add a diagnostic event specification
We're going to query the parameter color in the method PrintColor.
<DiagnosticEventSpecification>
<CategoryId>enumSample</CategoryId>
<SettingsName _locID="settingsName.ConsoleApplication.PrintColor">PrintColor (Color)</SettingsName>
<SettingsDescription _locID="settingsDescription.ConsoleApplication.PrintColor">
Print the color
</SettingsDescription>
<Bindings>
<Binding>
<ModuleSpecificationId>sample</ModuleSpecificationId>
<TypeName>ConsoleApplication1.Program</TypeName>
<MethodName>PrintColor</MethodName>
<MethodId>ConsoleApplication1.Program.PrintColor(System.Int32):System.Void</MethodId>
<ShortDescription _locID="shortDescription.PrintColor.Color">Print Color "{0}"</ShortDescription>
<LongDescription _locID="longDescription.PrintColor.Color">
Going to print the color in integral value "{0}"
</LongDescription>
<DataQueries>
<DataQuery index="0" type="Int32" name="color" query=""
_locID="dataquery.PrintColor.Color" _locAttrData="color"></DataQuery>
</DataQueries>
</Binding>
</Bindings>
</DiagnosticEventSpecification>
Save the file and restart VS. The custom event shows in Tools/Options/IntelliTrace/IntelliTrace Events
When I debug the program, the custom event appears in the Events table. Look at the description! It shows me the integral value of the enum value.
How simple it is to add a custom IntelliTrace event! This is helpful to diagnose a piece of code path that're prone to error in changes. When you have your own collection plan for the program, you can just debug the program and let it run, and spot the error from the Events table.