question

Dietmar-5258 avatar image
0 Votes"
Dietmar-5258 asked colinrippeyfinarne answered

ILogger structured loggig with Application Insights not working in .Net 5 Azure Function

Following the guide of creating the HttpExample for .Net 5 based Azure Functions, I'm failing setting up structured logging.

My relevant code is:

 [Function("HttpExample")]
 public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req, FunctionContext executionContext)
 {
     var logger = executionContext.GetLogger("HttpExample");
     logger.LogInformation("Example {ExampleValue}", 1001);

I would expect to get a logging record in Application Insights with a customDimensions property prop__ExampleValue, with a value of 1001.

This is however not the case. No matter what I try, I get the log entry as simple string, but not split into custom name/value pairs.

Any help would be highly appreciated.


Thanks in advance,
Dietmar




azure-functions
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @nasreen-akter,

many thanks for your reply.

I already tried this and this is working neither.

For me there is no way getting custom properties into the Applications Insights log. Should be easily reproducible with the vanilla HTTPExample. 3 simple tests which are all failing:

 logger.LogInformation("Example {ExampleValue}", 1001); //Logs only as a string, prop__ExampleValue missing

 using (_logger.BeginScope("ScopeTest"))
 {
     _logger.LogInformation("Scope logging test"); //Logs only the string, scope missing
 }

 Dictionary<string, string> certifcateProperties = new Dictionary<string, string>()
 {
     { "Prop1", "abc" },
     { "Prop2", "def" },
 };
  _logger.LogInformation("CustomProperties", certifcateProperties); //Logs only the string, dictionary content missing completely


Looks like a bug?


Thanks,
Dietmar

0 Votes 0 ·

1 Answer

colinrippeyfinarne avatar image
0 Votes"
colinrippeyfinarne answered

Hi @Dietmar-5258

I think I am seeing the same issue as you.

I am porting some simple in-process functions from a dotnet 3.1 function app to a new isolated .net 5 function app.

I am making simple log statements such as the one you have detailed above but when I check in app insights the structured logging capabilities are not working.

Looks like it is an active issue being tracked here:

https://github.com/Azure/azure-functions-host/issues/7452

The fix is tentatively scheduled for today based on sprint 108:

https://github.com/Azure/azure-functions-host/milestone/141

Maybe we'll get an update later today.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.