I am trying to get Serilog to work in my Azure Function App. I've just upgraded to .Net6, however, when the project starts, I'm getting this error for all the functions:
Microsoft.Azure.WebJobs.Host: Error indexing method 'MyFunctionName'.
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. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
I'm registering serilog in my startup like so:
public override void Configure(IFunctionsHostBuilder builder)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.CreateLogger();
builder.Services.AddLogging(lb =>
{
lb.AddSerilog(Log.Logger, true);
});
}
And digesting the ILogger in my functions like so:
public static class MyFunctionName
{
[FunctionName("MyFunctionName")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "my-function-path/{id}")] HttpRequestMessage req, int id, ILogger log)
{
// Do stuff
}
}
My csprojfile has the below in:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
...
<ItemGroup>
<PackageReference Include="AzureExtensions.Swashbuckle" Version="3.3.2" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="3.0.4" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
</ItemGroup>
Anyone have any ideas where I'm going wrong?
Thanks
Nick