ApplicationInsights-dotnet
Перейти к файлу
Timothy Mothra 518bf88345
Merge branch 'develop' into cijothomas/fixtransmissiontest
2019-11-14 13:01:46 -08:00
.images Tilee/reorg props (#1295) 2019-11-11 14:44:42 -08:00
.keys consolidating dependencies (#1269) 2019-10-28 14:51:01 -07:00
.props Tilee/reorg props (#1295) 2019-11-11 14:44:42 -08:00
.rulesets consolidating dependencies (#1269) 2019-10-28 14:51:01 -07:00
.scripts delete rulesets. delete old scripts. move scripts for future work. (#1303) 2019-11-14 11:03:49 -08:00
.targets Tilee/everything (#1275) 2019-11-07 13:22:11 -08:00
BASE Merge branch 'develop' into cijothomas/fixtransmissiontest 2019-11-14 13:01:46 -08:00
LOGGING consolidate changelog (#1302) 2019-11-14 12:44:57 -08:00
NETCORE consolidate changelog (#1302) 2019-11-14 12:44:57 -08:00
WEB consolidate changelog (#1302) 2019-11-14 12:44:57 -08:00
.gitattributes Migrate AspNetCoreSDK to Base repo (#1264) 2019-10-25 13:28:57 -07:00
.gitignore Tilee/reorg props (#1295) 2019-11-11 14:44:42 -08:00
CHANGELOG.Base.md consolidate changelog (#1302) 2019-11-14 12:44:57 -08:00
CHANGELOG.Logging.md consolidate changelog (#1302) 2019-11-14 12:44:57 -08:00
CHANGELOG.NetCore.md consolidate changelog (#1302) 2019-11-14 12:44:57 -08:00
CHANGELOG.Web.md consolidate changelog (#1302) 2019-11-14 12:44:57 -08:00
CHANGELOG.md consolidate changelog (#1302) 2019-11-14 12:44:57 -08:00
Directory.Build.props Tilee/everything (#1275) 2019-11-07 13:22:11 -08:00
EnlistmentRoot.marker Restructuring the Core SDK and CoreSDK Tests to fit the GitHub structure 2015-07-13 15:08:57 -07:00
Everything.sln Tilee/fix tests (#1301) 2019-11-13 14:22:29 -08:00
IntegrationTests.Readme.md Tilee/fix tests (#1301) 2019-11-13 14:22:29 -08:00
IntegrationTests.sln Tilee/fix tests (#1301) 2019-11-13 14:22:29 -08:00
LICENSE consolidating dependencies (#1269) 2019-10-28 14:51:01 -07:00
NuGet.config Tilee/everything (#1275) 2019-11-07 13:22:11 -08:00
ProjectsForSigning.sln Tilee/everything signing (#1296) 2019-11-11 14:50:07 -08:00
Readme.md Fix readme (#1267) 2019-10-25 16:04:32 -07:00

Readme.md

Please pardon our progress

We are currently in the process of consolidating our repos. This Readme will be updated as we make significant changes.

As of October 25, The contents of each former repo can be found in the sub folders; BASE, WEB, LOGGING, NETCORE.

NuGet packages

Base SDKs

Web SDKs

Logging Adapters

NetCore SDKs

Application Insights for .NET

This repository has code for the base .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 base 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 base 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 dependencies 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. More on SDK layering and extensibility later.

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 initialize 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 "base" 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 property data to each telemetry item sent. The TelemetryClient also exposes a number of Track...() methods that can be used to send all 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.
  • develop contains the code for the next release.

Contributing

We strongly welcome and encourage contributions to this project. Please read the general contributor's guide located in the ApplicationInsights-Home repository and the contributing guide for this SDK. 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 opencode@microsoft.com with any additional questions or comments.