如何使用BlobTrigger在AzureFunction应用程序中配置ILogger?

时间:2019-01-30 11:17:21

标签: c# azure-functions

我的代码:

using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace sampleapplication
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("testcontainer/{name}", Connection = "")]Stream myBlob, string name, ILogger log)
        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        }
    }
}

在运行应用程序时,

[30-01-2019 10:56:19] Run: 
 Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.Run'.
 Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'log' to type ILogger.
 Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.)
 make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

TraceWritter是默认设置,但跟踪编写器的单元测试用例无法执行。 所以我搜索了许多他们更喜欢Ilogger的网站。

如何在Azure Function App中初始化Ilogger?

1 个答案:

答案 0 :(得分:1)

使用运行时版本2.x创建函数,您将默认使用Ilogger。请参见下面的屏幕截图:

screenshot

相关问题