Skip to content

Commit

Permalink
Update repo to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McCabe committed Apr 19, 2020
1 parent 9f440a1 commit c11ad1b
Show file tree
Hide file tree
Showing 12 changed files with 702 additions and 187 deletions.
84 changes: 75 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# **Cloud.Core.Telemetry.AzureAppInsights**
# **Cloud.Core.Telemetry.AzureAppInsights** [![Build status](https://dev.azure.com/cloudcoreproject/CloudCore/_apis/build/status/Cloud.Core/Cloud.Core.Telemetry.AzureAppInsights_Package)](https://dev.azure.com/cloudcoreproject/CloudCore/_build/latest?definitionId=10) ![Code Coverage](https://cloud1core.blob.core.windows.net/codecoveragebadges/Cloud.Core.Telemetry.AzureAppInsights-LineCoverage.png)
[![Cloud.Core.Configuration package in Cloud.Core feed in Azure Artifacts](https://feeds.dev.azure.com/cloudcoreproject/dfc5e3d0-a562-46fe-8070-7901ac8e64a0/_apis/public/Packaging/Feeds/8949198b-5c74-42af-9d30-e8c462acada6/Packages/e71ddf20-f66a-45da-b672-c32798cf1e51/Badge)](https://dev.azure.com/cloudcoreproject/CloudCore/_packaging?_a=package&feed=8949198b-5c74-42af-9d30-e8c462acada6&package=e71ddf20-f66a-45da-b672-c32798cf1e51&preferRelease=true)


<div id="description">

<div id="description">
Azure specific implementation of telemetry logging. Uses the ITelemeteryLogger interface from _Cloud.Core_ and can be used in conjunction with the Telemetry Logging
Provider classes found in the _Cloud.Core.Telemetry.Logging_ package.

</div>

## Usage
Expand All @@ -24,26 +25,91 @@ Any of the logging methods can also handle exception, such as:

```csharp
logger.LogWarning(new Exception("Something's gone wrong!"));
``

## Config

There are a number of ways to create an instance of the AppInsights logger, the simpliest and most direct way is the following:

```csharp
var logger = new AppInsightsLogger("instrumentationKey", LogLevel.Debug);
```

However, typical use case is as an instance of the `ITelemetryLogger` interface and with an IServiceCollection (in a Startup.cs file). Therefore, leveraging the extensions methods that have been built for convenience as follows during the Logger configuration is probably easier:

```csharp
public class Startup
{
public void ConfigureAppConfiguration(IConfigurationBuilder builder)
{
// Read config from config sources...
builder.UseKubernetesContainerConfig();
}

public void ConfigureLogging(IConfiguration config, ILoggingBuilder builder)
{
builder.AddConfiguration(config.GetSection("Logging"));

// Add some default loggers.
builder.AddConsole();
builder.AddDebug();

// Add your app insights telemetry logger here!
// 1. Implicitly using instrumentation key.
builder.AddAppInsightsLogger();

// 2. Explicitly specifying the instrumentation key.
var instrumentationKey = config.GetValue<string>("InstrumentationKey");
builder.AddAppInsightsLogger(instrumentationKey);
}

public void ConfigureServices(IConfiguration config, ILogger logger, IServiceCollection services)
{
// Configure services...
}
}
```

If you use the first example (implicitly AddingAppInsightsLogger) without specifying config, the code will look for the instrumentation key in one of the following config settings:

1. _InstrumentationKey_
2. _APPINSIGHTS_INSTRUMENTATIONKEY_
3. _Logging:InstrumentationKey_
4. _AppInsights:InstrumentationKey_

If It cannot find it here, it will throw an invalid argument exception.

The second example (explicit setting of instrumentation key), you pass it an instruementation key you have loaded yourself.

Both examples will look for log level from config specified in the "Logging:LogLevel:Telemetry" setting. If it cannot find that, it will default to _Logging:LogLevel:Default_ for its setting. Failing that, it falls back to info.

## Further Reading

Read more about logging providers and filters here:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1

## Test Coverage
A threshold will be added to this package to ensure the test coverage is above 80% for branches, functions and lines. If it's not above the required threshold
(threshold that will be implemented on ALL of the new core repositories going forward), then the build will fail.
(threshold that will be implemented on ALL of the core repositories to gurantee a satisfactory level of testing), then the build will fail.

## Compatibility
This package has has been written in .net Standard and can be therefore be referenced from a .net Core or .net Framework application. The advantage of utilising from a .net Core application,
is that it can be deployed and run on a number of host operating systems, such as Windows, Linux or OSX. Unlike referencing from the a .net Framework application, which can only run on
Windows (or Linux using Mono).

## Setup
This package requires the .net Core 2.1 SDK, it can be downloaded here:
https://www.microsoft.com/net/download/dotnet-core/2.1
This package is built using .net Standard 2.1 and requires the .net Core 3.1 SDK, it can be downloaded here:
https://www.microsoft.com/net/download/dotnet-core/

IDE of Visual Studio or Visual Studio Code, can be downloaded here:
https://visualstudio.microsoft.com/downloads/

## How to access this package
All of the Cloud.Core.* packages are published to our internal NuGet feed. To consume this on your local development machine, please add the following feed to your feed sources in Visual Studio:
TBC

All of the Cloud.Core.* packages are published to a internal NuGet feed. To consume this on your local development machine, please add the following feed to your feed sources in Visual Studio:
https://pkgs.dev.azure.com/cloudcoreproject/CloudCore/_packaging/Cloud.Core/nuget/v3/index.json
For help setting up, follow this article: https://docs.microsoft.com/en-us/vsts/package/nuget/consume?view=vsts


<img src="https://cloud1core.blob.core.windows.net/icons/cloud_core_small.PNG" />
5 changes: 4 additions & 1 deletion src/Cloud.Core.Telemetry.AzureAppInsights.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=F0CD7CC0_002DBDAB_002D4AA8_002D8C5B_002D0D5829C6820F/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CollectionNeverUpdated_002EGlobal/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CollectionNeverUpdated_002ELocal/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StaticMemberInGenericType/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CSharpWarnings_003A_003AWME006/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EmptyNamespace/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ResxNotResolved/@EntryIndexedValue">SUGGESTION</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ResxNotResolved/@EntryIndexedValue">SUGGESTION</s:String>
<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/IntelliSenseCompletingCharacters/CSharpCompletingCharacters/UpgradedFromVSSettings/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=NotResolvedInText/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnassignedGetOnlyAutoProperty/@EntryIndexedValue">SUGGESTION</s:String>
Expand Down
Loading

0 comments on commit c11ad1b

Please sign in to comment.