Skip to content

madskristensen/VsixLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vsix Logger

Build status

Adds logging and telemetry support to Visual Studio extensions.

Available as VsixLogger on NuGet


Features

  • 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

Referenced assemblies

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

Initialize the logger

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.

Logger

Here's is how to initialize the logger.

protected override void Initialize()
{
  base.Initialize();
  Logger.Initialize(this, "Vsix name");
}

Logger + Telemetry

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");
}

API

Logger

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.

Exceptions

try {
  // code
}
catch (Exception ex){
  Logger.Log(ex);
}

Any string

  Logger.Log("Some string");

Telemetry

The Telemetry class allows you to track both exceptions and custom events with Application Insights.

Exceptions

It's recommended to use Logger.Log(Exception) to log exceptions.

try {
  // code
}
catch (Exception ex){
  Telemetry.TrackException(ex);
}

Events

  Telemetry.TrackEvent("event name", properties = null, metrics = null);

Contribute

Bug reports and pull requests are more than welcome.

License

Apache 2.0

About

A helper library for Visual Studio extensions

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published