English
Français

Blog of Denis VOITURON

for a better .NET world

Application Insights for your WebAPI

Application Insights is a feature of Azure Monitor. It is an extensible service of Application Performance Management (APM). Use it to monitor your application. It will automatically detect performance anomalies. It includes powerful analysis tools to help you diagnose problems and understand what users are actually doing with your application.

1. Enable Application Insights.

To use this service, it is very simple.

  1. Simply add this service Application Insights to your Azure portal. If you already have a App Service (for your website, for example), you already have the service. Retrieve the Instrumentation Key key from the Overview screen of the Application Insights service.

  2. In your ASP.NET Core project, add the NuGet package ApplicationInsights.

  3. Refer this new service to your Startup class: services.AddApplicationInsightsTelemetry();

  4. Create or modify your file appsettings.json by specifying the Instrumentation Key:

{
  "ApplicationInsights": {
    "InstrumentationKey": "2212b9e0-4715-1765-1746-12cbe02edd67"
  }    
}

Start your project and navigate through the APIs or screens. After a few seconds, you will see the traces appear in the Azure portal.

Application Insights Demo


Blazor Code Behind (partial class)

UPDATE: On October 15th 2019, Microsoft announced the partial class support. This article is the update version of the article of october 6th.

If, like me, you start developing projects with Blazor, you may prefer to separate your HTML code from your CSharp code.

Indeed, all the examples presented by Microsoft use this format, where the code is injected from the web page via the @code attribute.

<!-- File "Counter.razor" -->
@page "/counter"

<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button @onclick="IncrementCount">Click me</button>

@code {
    int currentCount = 0;

    void IncrementCount()
    {
        currentCount++;
    }
}

Personally, I prefer to decompose the visual into a .razor file and the CSharp code into a .razor.cs file. This file contains a partial class named as the component.


GIT authentication

To connect to Azure DevOps, there are several ways to authenticate. One of the easiest ways to do this, under Windows, is to use GIT Credential Manager. This GIT Credential Manager creates and registers a Personal Access Token by opening a connection window to Azure DevOps.

Sometimes the Token is invalid. You must then ask to generate a new one.

\> git fetch
remote: TF401019: The Git repository with name or identifier MyProject does not exist or you do not have permissions for the operation you are attempting.
fatal: repository 'https://dev.azure.com/.../MyProject/_git/MyProject/' not found

Blazor Code Behind

UPDATE: On October 15th 2019, Microsoft announced the partial class support. A new version of this article is here.

If, like me, you start developing projects with Blazor, you may prefer to separate your HTML code from your CSharp code.

Indeed, all the examples presented by Microsoft use this format, where the code is injected from the web page via the @code attribute.

<!-- File "Counter.razor" -->
@page "/counter"

<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button @onclick="IncrementCount">Click me</button>

@code {
    int currentCount = 0;

    void IncrementCount()
    {
        currentCount++;
    }
}

Personally, I prefer to decompose the visual into a .razor file and the CSharp code into a .razor.cs file. It is done without difficulties, by creating:

  1. A Counter.razor file that refers to the class via @inherits.
  2. A CounterBase class that inherits from ComponentBase.

Event ReBUILD 2019

This Thursday, October 3, the community event ReBUILD was held in Nantes.

Adrien Clerbois and me, had the opportunity to present two sessions on DevOps technologies.

Here are the slides (in french).


Azure DevOps - Compile with .NETCore 3

Since few days Microsoft released the final version of .NETCore 3.0.

How to develop with .NET Core 3.0

To use this version, configure your csproj to define the TargetFramework and the parameters of publication : a single file for Win10-x64.

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
    <PublishSingleFile>true</PublishSingleFile>
    <PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

You can publish your project in a single big executable, via the Visual Studio command Publish (right-click on the project).


AspNetCore WebAPI - Google Authentication

More and more projects have sections secured by Google, Twitter or Microsoft identities. For example, for Google, you must create an ID and specify the return URL. Then you must activate the Google Authentication service and secure your methods via [Authorize]. The first call of a secure method automatically redirects you to the Google page.


Azure for Dev

Here are the slides of my presentation used during the Hack in the Woods 2019. You will find interesting services and tools to start developments.


Visual Studio - GIT shortcuts

If, like me, you work regularly with Visual Studio and GIT Team Explorer, here are some useful shortcuts.


Azure DevOps and the Code Coverage

Although Microsoft offers a solution to calculate natively the code coverage, it generates several problems: difference in results between the Build Server and “Visual Studio / Test / Analyze Code coverage”, code coverage problem with referenced assemblies, etc.


Languages

EnglishEnglish
FrenchFrançais

Follow me

Recent posts