Update
What is the difference between ILoggerFactory and ILogger<> with MS logging on Azure Functions 2, which supports Application Insights?
Code below:
public class Functions
{
//other code
private ILogger _log;
public Functions(ILoggerFactory loggerFactory, ILogger<Functions> log)
{
_log = loggerFactory.CreateLogger<Functions>();
_log = log;
}
[FunctionName("Token")]
public async Task<IActionResult> Function1(
[HttpTrigger()]...)
{
_log.LogInformation("Function1 invoked");
}
}
Update 2
ILogger: If ILogger is used as constructor parameter, the error below occurs. It works if it is used as function parameter.
What is the service lifetime for ILogger instance?
Is there a plan to support it on CTOR?
[04/06/2019 10:06:12] Executed 'SampleFunction' (Failed, Id=3912a5b7-10fa-41e1-9
0f8-fba9d2cda49b)
[04/06/2019 10:06:12] Microsoft.Extensions.DependencyInjection.Abstractions: Una
ble to resolve service for type 'Microsoft.Extensions.Logging.ILogger' while att
empting to activate 'Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.
SampleFunction'.
[04/06/2019 10:06:12] An unhandled host error has occurred.
[04/06/2019 10:06:12] Microsoft.Extensions.DependencyInjection.Abstractions: Una
ble to resolve service for type 'Microsoft.Extensions.Logging.ILogger' while att
empting to activate 'Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.
SampleFunction'.