Adds logging and telemetry support to Visual Studio extensions.
Available as VsixLogger on NuGet
- Easy to setup and use
- Logs any string message to Output Window
- Logs any exception to Output Window
- Logs any exception to Application Insights
- Tracks custom events through Application Insights
This package will automatically install Microsoft.VisualStudio.Shell.Interop into the VSIX project.
You must manually add a reference to the following assemblies for it to work:
- EnvDTE
- EnvDTE80
From the Visual Studio extension's package file's Initialize()
method, call Logger.Initialize()
to set everything up. This
is the only thing needed to be able to start using the logger.
Here's is how to initialize the logger.
protected override void Initialize()
{
base.Initialize();
Logger.Initialize(this, "Vsix name");
}
Here's is an example on how to initialize the logger as well as the Application Insights telemetry.
protected override void Initialize()
{
base.Initialize();
Logger.Initialize(this, "Vsix name", "Version", "177c7fed-9dec-4947-b29d-5d3ff53a50e3");
}
Use the Logger.Log
method to log exceptions or strings to
the Output Window. If the Telemetry
client has been
initialized then exceptions are logged to Application Insights
as well.
try {
// code
}
catch (Exception ex){
Logger.Log(ex);
}
Logger.Log("Some string");
The Telemetry
class allows you to track both exceptions
and custom events with Application Insights.
It's recommended to use Logger.Log(Exception)
to log
exceptions.
try {
// code
}
catch (Exception ex){
Telemetry.TrackException(ex);
}
Telemetry.TrackEvent("event name", properties = null, metrics = null);
Bug reports and pull requests are more than welcome.