In this tutorial we are going to see what are the various ways to add custom properties in application insights.
- Direct in Logger
- Using Scopes
- Using Telemetry Client
- Using Telemetry Initializer
- Using Telemetry Processor
Direct in Logger:
When ever you give message to Log Methods if you pass parameters and value in methods using {paramname}, then this will consider as custom properties. for example below two custom properties are there one is Id another one is AuthorTimeStamp.
Using Scopes:
Using BeginScope we can pass the Custom Properties for entire scope, that means whatever log method is inside this scope will add this custom properties. Both LogDebug and LogError will have AuthorRequest and AuthorId Custom Properties.
Using Telemetry Client:
This is a direct message added using Telemetry client where you can add the custom properties with the telemetry. for example we are using below ExceptionTelemetry and TraceTelemetry.
Using Telemetry Initializer:
This will run in pipeline before telemetries are send to Azure monitor. In below code we are attaching or adding one custom property to all Trace Telemetry.
Using Telemetry Processor:
This will run in pipeline after Telemetry Initializer, Here we are adding custom property to Request Telemetry when it have response code 200.
From this tutorial you can learn how to add the Custom properties in various ways in application insights.