Plinth.Logging.NLog.AppInsights 1.5.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
.NET 6.0
dotnet add package Plinth.Logging.NLog.AppInsights --version 1.5.0
NuGet\Install-Package Plinth.Logging.NLog.AppInsights -Version 1.5.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plinth.Logging.NLog.AppInsights" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plinth.Logging.NLog.AppInsights --version 1.5.0
#r "nuget: Plinth.Logging.NLog.AppInsights, 1.5.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plinth.Logging.NLog.AppInsights as a Cake Addin
#addin nuget:?package=Plinth.Logging.NLog.AppInsights&version=1.5.0

// Install Plinth.Logging.NLog.AppInsights as a Cake Tool
#tool nuget:?package=Plinth.Logging.NLog.AppInsights&version=1.5.0

README

Plinth.Logging.NLog.AppInsights

Integration allowing Plinth and NLog to record telemetry and logs to Azure Application Insights

1. Add this to your NLog.config under the <nlog> tag

  <extensions>
    <add assembly="Plinth.Logging.NLog.AppInsights" prefix="plinthAI" />
  </extensions>

2. Then create the target

  <targets>
    <target xsi:type="plinthAI.AppInsightsTarget" name="aiTarget">
      <connectionString>{from-Azure-Portal}</connectionString>
      <cloudRoleName>testRole1</cloudRoleName>
      <cloudRoleInstance>serverA</cloudRoleInstance>
      <maxLength>25000</maxLength>
    </target>
  </targets>
  • 👉 Do not wrap this in an async wrapper. It will break the context and metadata.
  • cloudRoleName and cloudRoleInstance are optional, and will have reasonable defaults if not specified
  • Cloud Role Name is typically the application name
  • Cloud Role Instance is typically the machine name
  • The maxLength field is optional, and defaults to 25000 characters
  • 👉 Using a connection string is preferred. <instrumentationKey> is supported but deprecated and will stop working in March 2025

3. Reference the target in a logger rule

  <rules>
    <logger name="*" minlevel="Debug" writeTo="aiTarget" />
  </rules>

4. Initialize telemetry in Startup

  services.AddPlinthAppInsightsTelemetry(cfg => 
  {
      cfg.CloudRoleName = "MyApp";
      cfg.DisabledPrefixes.Add("/health");
  });

👉 The lambda is optional and only necessary if setting hardcoded configuration

Configurations Options are

  • ConnectionString: If not setting via environment variable or NLog.config
  • DisabledPrefixes: A blacklist of url prefixes to disable Request Telemetry. Example: "/favicon.ico"
  • EnabledPrefixes: A whitelist of url prefixes to enable Request Telemetry. This is null by default. If a list of prefixes is specified, only requests which match will have request telemetry. If there is a conflict between this and DisabledPrefixes, the preference is to disable telemetry.
  • CaptureSqlCommandText: Set to true to have SQL Dependency Telemetry capture the SQL command text sent to the database. Defaults to false.
  • CloudRoleName: See next section
  • CloudRoleInstance: See next section

5. Application Insights Configuration Settings

Values are applied in this order of precedence

  • Connection String (get this from the Azure Portal)

    1. Hardcoded parameter passed in Startup.cs (does not apply to NLog logs)
    2. NLog.config <connectionString>
    3. Environment variable: APPLICATIONINSIGHTS_CONNECTION_STRING
    4. (Obsolete): NLog.config <instrumentationKey>
    5. (Obsolete): Environment variable APPINSIGHTS_INSTRUMENTATIONKEY
  • Cloud Role Name

    1. Hardcoded parameter passed in Startup.cs (does not apply to NLog logs)
    2. NLog.config <cloudRoleName>
    3. Environment variable: APPLICATIONINSIGHTS_CLOUD_ROLENAME
  • Cloud Role Instance

    1. Hardcoded parameter passed in Startup.cs (does not apply to NLog logs)
    2. NLog.config <cloudRoleInstance>
    3. Environment variable: APPLICATIONINSIGHTS_CLOUD_ROLEINSTANCE
Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0 66 11/9/2022
1.5.0-b88.7a7c20cd 32 11/9/2022
1.4.7 281 10/20/2022
1.4.6 223 10/17/2022
1.4.5 334 10/1/2022
1.4.4 207 8/16/2022
1.4.3 209 8/2/2022
1.4.2 400 7/19/2022
1.4.2-b80.7fdbfd04 75 7/19/2022
1.4.2-b74.acaf86f5 58 6/15/2022
1.4.1 235 6/13/2022
1.4.0 229 6/6/2022
1.3.8 880 4/12/2022
1.3.7 279 3/21/2022
1.3.6 278 3/17/2022
1.3.6-b67.ca5053f3 66 3/16/2022
1.3.6-b66.4a9683e6 63 3/16/2022
1.3.5 322 2/23/2022
1.3.4 617 1/20/2022
1.3.3 188 12/29/2021
1.3.2 355 12/11/2021
1.3.1 220 11/12/2021
1.3.0 241 11/8/2021
1.2.3 1,421 9/22/2021
1.2.2 255 8/20/2021
1.2.1 244 8/5/2021
1.2.0 309 8/1/2021
1.2.0-b37.a54030b9 106 6/24/2021
1.1.6 2,648 3/22/2021
1.1.5 456 3/9/2021
1.1.4 343 2/27/2021
1.1.3 331 2/17/2021
1.1.2 369 2/12/2021
1.1.1 378 2/1/2021
1.1.0 409 12/16/2020
1.1.0-b27.b66c309b 231 11/15/2020
1.0.12 514 10/18/2020
1.0.11 428 10/6/2020

net7.0 support and removed netcoreapp3.1