question

AviStokar-8063 avatar image
0 Votes"
AviStokar-8063 asked AviStokar-8063 answered

Azure Functions Logger using DI - examples in docs dont work

I am unable to get my own logger to log when using DI in Azure Functions. I have attached a very simple project which does not work. I have tried using Serilog (as in the attached example) or without it. Neither logs anything.

Additionally, I would like to use a non-generic ILogger, but that causes the DI container to crash with a unable to create an ILogger instance. (Unable to resolve ILogger from Microsoft.Extensions.Logging)


[1]: /answers/storage/attachments/115059-function1cs.txt

[2]: /answers/storage/attachments/115103-hostjson.txt

[3]: /answers/storage/attachments/115048-localsettingsjson.txt

[4]: /answers/storage/attachments/115064-startupcs.txt


azure-functions
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.

1 Answer

AviStokar-8063 avatar image
0 Votes"
AviStokar-8063 answered

I found the problem - I had copied the host.json from the example at docs https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
},
"logLevel": {
"MyNamespace.HttpTrigger": "Information"
}
}
}
removing the "excludedTypes": "Request" allows the logged messages to appear in the application insights log; however, theu still do not appear in the log stream, even when setting the loglevel using the nameapce (as instructed above in the docs) or adding a default in the loglevel.

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.