All posts by Kevin

About Kevin

IoT & Azure ML Learner

Azure Application Insights customEvents and .NET 6

Getting customEvents with Azure Application Insights customEvents and .NET 6

dotnet new mvc -o videowebapp
cd videowebapp
dotnet add package Microsoft.ApplicationInsights.AspNetCore

Program.cs: Adding builder.Services.AddApplicationInsightsTelemetry();

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
IServiceCollection serviceCollection = builder.Services.AddApplicationInsightsTelemetry();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see




    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");


Getting InstrumentationKey

az resource show \
    --resource-group <resource_group_name> \
    --name <resource_name> \
    --resource-type "Microsoft.Insights/components" \
    --query properties.InstrumentationKey

appsettings.json : adding InstrumentationKey

  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
  "AllowedHosts": "*",
  "ApplicationInsights": {
    "InstrumentationKey": "0000000000000000000000000000000",
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Error"

HomeController.cs : Adding ” this.aiClient.TrackEvent(“CommentSubmitted”); ”

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using videowebapp.Models;
using Microsoft.ApplicationInsights;

namespace videowebapp.Controllers;

public class HomeController : Controller
    private TelemetryClient aiClient;
 //   private readonly ILogger<HomeController> _logger;

public HomeController(TelemetryClient aiClient)
    this.aiClient = aiClient;
/*    public HomeController(ILogger<HomeController> logger)
        _logger = logger;
    public IActionResult Index()
       // _logger.LogWarning("fujuTE: An example of a Warning trace..");
       // _logger.LogError("fujuTE: An example of an Error level message");
        return View();

    public IActionResult Privacy()
        // _logger.LogInformation("fujuTE: An example of a Information trace..");
        // Track an event

        // Track an event with properties
        this.aiClient.TrackEvent("VideoUploaded", new Dictionary<string, string> {{"Category", "Sports"}, {"Format", "mp4"}});

        return View();

    [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
    public IActionResult Error()
        return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
Application Insight – Transaction Search
Getting customEvents vai Log Analytics Workspace

See Also:

Create Azure Service Principal and “az login”

Sample of creating Resource Group and then create Service Principle with contributor role under the RG for DevOps Pipeline

#az group create --name $MY_RG --location southeastasia
#RG_ID=$(az group show --name $MY_RG --query "id" --output tsv)
# or 
RG_ID=$(az group create --name $MY_RG  --location southeastasia --query "id" --output tsv)
PASSWORD=$(az ad sp create-for-rbac --name $SERVICE_PRINCIPAL_NAME --role contributor --scopes $RG_ID  --query "password" --output tsv)
USER_NAME=$(az ad sp list --display-name $SERVICE_PRINCIPAL_NAME --query "[].appId" --output tsv)

az login --service-principal -u $USER_NAME -p $PASSWORD --tenant <mytenant>

How to build real world cloud applications using Windows Azure

How to build real world cloud applications using Windows Azure

Part 1: Building Real World Cloud Apps with Azure
  Part 2: Building Real World Cloud Apps with Azure
Free ebook: Building Cloud Apps with Microsoft Azure

Four Principles of Engineering Scalable, Big Data Software Systems from CMU


Four Principles of Engineering Scalable, Big Data Software Systems By Ian Gorton
Senior Member of the Technical Staff
Software Solutions Division

  • First Principle: System Costs Must Grow More Slowly Than System Capacity
  • Second Principle: The More Complex a Solution, the Less Likely it Will Scale
  • Third Principle: Avoid Managing Conversational State Outside the Data Tier
  • Fourth Principle: You Can’t Manage What You Don’t Monitor

Steps to Success

ได้มาจากข้อความที่ติดในโรงเรียนอนุบาล เข้าใจว่าให้ทั้งคุณครูและนักเรียนอนุบาลอ่าน

The Top 10  Steps to Success
 2.Try again
 3.Try once more
 4.Try it a little differently
 5.Try it again tomorrow
 6.Try and ask for help
 7.Try to find someone who’s done it
 8.Try to determine what is not working
 9.Try to determine what is working
 10.Just keep trying

ไม่ว่าจะผ่านไปกี่ปีการต่อสู้กับตนเองก็ยังเกิดขึ้นทุกว้น เกิดขึ้นกับรูปแบบของปัญหาที่ซับซ้อนมากขึ้น และกับความต้องการที่ซับซ้อนมากขั้นด้วยเช่นกัน

(ref: )