i am trying to get structured logging working in a Azure Function, but it does not work on my side.
I wrote a simple application like this
[FunctionName("Dummy")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous)]HttpRequest request, ILogger log)
{
var instance = new User
{
Name1 = "foo",
Name2 = "bar"
};
log.LogInformation("Test1: {$Test}", instance);
log.LogInformation("Test2: {@Name}", instance);
log.LogInformation("Test3: {@Name}", new { Name1 = "abc", Name2 = "def" });
log.LogInformation("Test4: {Vorname} {Nachname}", instance.Name1, instance.Name2);
return new OkResult();
}
public class User
{
public string Name1 { get; set; }
public string Name2 { get; set; }
}
and the output looks like this:
Test1: Company.FunctionApp1.Function+User
Test2: Company.FunctionApp1.Function+User
Test3: { Name1 = abc, Name2 = def }
Test4: foo bar
I have no clue why the destructure is working on the dynamic type but not on the defined class. I have found many examples for normal logging with no destructure of a object, but i thought that it should work out of the box.
Am i missing something?