【发布时间】:2019-10-18 01:48:02
【问题描述】:
更新
在支持 Application Insights 的 Azure Functions 2 上使用 MS 日志记录的 ILoggerFactory 和 ILogger 有什么区别?
代码如下:
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");
}
}
更新 2
日志记录器: 如果使用 ILogger 作为构造函数参数,则会出现以下错误。 如果用作函数参数,它就可以工作。
ILogger 实例的服务生命周期是多少?
是否有计划在 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'.
【问题讨论】:
标签: azure azure-functions azure-functions-runtime