Code Monkey home page Code Monkey logo

applicationinsights-dotnet's Introduction

Build Status Nuget codecov.io

Application Insights for .NET

This repository has code for the core .NET SDK for Application Insights. Application Insights is a service that allows developers ensure their application are available, performing, and succeeding. This SDK provides the core ability to send all Application Insights types from any .NET project.

Getting Started

If developing for a .Net project that is supported by one of our platform specific packages, Web or Windows Apps, we strongly recommend to use one of those packages instead of this core library. If your project does not fall into one of those platforms you can use this library for any .Net code. This library should have no depenedencies outside of the .Net framework. If you are building a Desktop or any other .Net project type this library will enable you to utilize Application Insights.

Get an Instrumentation Key

To use the Application Insights SDK you will need to provide it with an Instrumentation Key which can be obtained from the portal. This Instrumentation Key will identify all the data flowing from your application instances as belonging to your account and specific application.

Add the SDK library

We recommend consuming the library as a NuGet package. Make sure to look for the Microsoft.ApplicationInsights package. Use the NuGet package manager to add a reference to your application code.

Initialize a TelemetryClient

The TelemetryClient object is the primary root object for the library. Almost all functionality around telemetry sending is located on this object. You must intiialize an instance of this object and populate it with your Instrumentation Key to identify your data.

using Microsoft.ApplicationInsights;

var tc = new TelemetryClient();
tc.InstrumentationKey = "INSERT YOUR KEY";

Use the TelemetryClient to send telemetry

This "core" library does not provide any automatic telemetry collection or any automatic meta-data properties. You can populate common context on the TelemetryClient.context property which will be automatically attached to each telemetry item sent. You can also attach additional propety data to each telemetry item sent. The TelemetryClient also exposes a number of Track...() methods that can be used to send all core telemetry types understood by the Application Insights service. Some example use cases are shown below.

tc.Context.User.Id = Environment.GetUserName(); // This is probably a bad idea from a PII perspective.
tc.Context.Device.OperatingSystem = Environment.OSVersion.ToString();

tc.TrackPageView("Form1");

tc.TrackEvent("PurchaseOrderSubmitted", new Dictionary<string, string>() { {"CouponCode", "JULY2015" } }, new Dictionary<string, double>() { {"OrderTotal", 68.99 }, {"ItemsOrdered", 5} });
	
try
{
	...
}
catch(Exception e)
{
	tc.TrackException(e);
}

Ensure you don't lose telemetry

This library makes use of the InMemoryChannel to send telemetry data. This is a very lightweight channel implementation. It stores all telemetry to an in-memory queue and batches and sends telemetry. As a result, if the process is terminated suddenly, you could lose telemetry that is stored in the queue but not yet sent. It is recommended to track the closing of your process and call the TelemetryClient.Flush() method to ensure no telemetry is lost.

Full API Overview

Read about how to use the API and see the results in the portal.

Branches

  • master contains the latest published release located on NuGet.
  • development contains the code for the next release.

Contributing

We strongly welcome and encourage contributions to this project. Please read the contributor's guide located in the ApplicationInsights-Home repository. If making a large change we request that you open an issue first. We follow the Git Flow approach to branching.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

applicationinsights-dotnet's People

Contributors

abaranch avatar regexrowboat avatar cijothomas avatar vitalyf007 avatar kartang avatar dnduffy avatar upendras avatar izikl avatar tokaplan avatar assaf-neufeld avatar jawn avatar ericmaino avatar jakuboleksy avatar mousetraps avatar iziklisbon avatar smarts avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.