Search code examples
azureazure-application-insightskqlazure-log-analytics

Azure log analytics severity level as string


Currently in azure application insights we see under severityLevel the number of ther severity level and not the text like information, error,... Is it possible to show the severityLevel as a string.

enter image description here

"Serilog": {
"Using": [
    "Serilog.Sinks.ApplicationInsights"
],
"MinimumLevel": {
    "Default": "Debug",
    "Override": {
        "Microsoft": "Information"
    }
},
"WriteTo": [
    {
        "Name": "ApplicationInsights",
        "Args": {
            "restrictedToMinimumLevel": "Information",
            "telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights",
            "instrumentationKey": "key"
        }
    }
],
"Enrich": [
    "FromLogContext"
],
"Properties": {
    "Application": "Sample"
}
}

Solution

  • Ad hoc function, using let statement

    // Sample generation. Not part of the solution
    let traces = materialize(range i from 1 to 10 step 1 | project severityLevel = toint(rand(5)), Timestamp = ago(rand()*1d));
    // Solution starts here
    let getSeverityDescription = (severityLevel:int)
    {
        dynamic(["Verbose", "Information", "Warning", "Error", "Critical"])[severityLevel]
    };
    traces
    | extend SeverityDescription = getSeverityDescription(severityLevel)
    
    severityLevel Timestamp SeverityDescription
    3 2022-06-29T11:56:30.3936027Z Error
    4 2022-06-29T15:08:45.0941469Z Critical
    4 2022-06-30T03:02:29.1658275Z Critical
    1 2022-06-30T03:29:22.4724933Z Information
    0 2022-06-30T04:01:15.7748102Z Verbose
    0 2022-06-30T04:37:39.740977Z Verbose
    2 2022-06-30T05:13:04.734582Z Warning
    2 2022-06-30T07:32:01.9569582Z Warning
    2 2022-06-30T07:41:46.3364296Z Warning
    1 2022-06-30T09:42:22.5852665Z Information

    Fiddle