Search code examples
loggingazure-application-insightsasp.net-core-3.1serilog.net-5

Log Application Insight custom dimensions using serilog


I would like to enrich the serilog trace message with some customized information (for example the user role, the business solution..) and I would like to see those properties into the Application Insight "Custom Dimension" field. I tried to look around but I didn't find a proper solution. I'm using ASP.NET Core 3.1


Solution

  • As op said in the comment, there is a suggestion on this case.

    Basicly,when we use serilog with application insights, we usually set custom dimensions like this:

    var position = new { Latitude = 25, Longitude = 134 }; 
    var elapsedMs = 34; 
    var numbers = new int[] { 1, 2, 3, 4 };  
    Logger.Information("Processed {@Position} in {Elapsed:000} ms., str {str}, numbers: {numbers}", position, elapsedMs, "test", numbers);