2

I have set up application insights for asp.net core project.

appsettings.json:

  "ApplicationInsights": {
    "InstrumentationKey": "90f786b7-36a5-xxxx-b1fc-xxxxxxxxx"
  },

Startup.cs:

services.AddApplicationInsightsTelemetry();

And in my controller I can now log:

Logger.LogDebug("LogDebug");

I cant find any information on how to set CustomDemensions. I can see on the overloads there is an object array but not sure if that if for customdimensions. Any pointers?

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
Thomas Segato
  • 4,567
  • 11
  • 55
  • 104

1 Answers1

3

Updated:

            var dict = new Dictionary<string, object> { { "user_name","ivan"},{ "mycity","new york"} };

            using (_logger.BeginScope(dict))
            {
                _logger.LogInformation("this is a test message for testing purpose 456");
            }

Original answer:

For example, if you want to add the 2 properties city / user in customDimentions, please use the code below in the controller:

string city = "london";
string user = "jack";
_logger.LogInformation("{user} sends a  message from {city}", user, city);

Then in azure portal -> application insights logs:

enter image description here

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60