I have a C# .NET Core Azure Function App, and I am using the ILogger to send logs to Application Insights. This is working well so far.
Function header:
public static void Run([TimerTrigger("0 30 * * * *")] TimerInfo myTimer, ILogger log, ExecutionContext context)
ILogger usage:
log.LogInformation($"MyFunction trigger function executed at: {DateTime.Now}");
In App Insights, I see the log which has default information like which Function App it came from, as well as the message
which contains the above string.
However, now I want to log a custom log. I have an IEnumerable<IDictionary<string, string>>
and I want each dictionary element of the list to be a separate log. Ideally, I could have a log with each field being a key from the dictionary, and its value to be the corresponding value. Alternatively, I would be fine with some sort of customDimensions field in the log, which would be an object containing all the key-value pairs from 1 dictionary in the list.
The intent is to make the logs simple to query in Kusto. I want to avoid having to parse them when querying them in App Insights.
Notes:
- since I already use the ILogger for existing logging, is there a way to do the above object-logging with the ILogger interface?
- if not, how can I log an object like mentioned above with a different logger?
I looked at numerous other similar posts, but none of them seemed to be fully answered.