我在本地有两个相同的Azure Functions V2项目。 这两个项目具有相同的配置,nuget库版本,SDK,代码,startup.cs,CLI和函数运行时版本。基本上,它们是相同的。但是,按预期方式,写入该功能中的ILogger实例的日志会出现在CLI上,这与预期的一样,但另一个丢失了CLI上的消息!
两个项目的Functions.csproj;
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="3.4.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="3.0.6" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Startup.cs;
[assembly: FunctionsStartup(typeof(FunctionAppLogTest.Startup))]
namespace FunctionAppLogTest
{
public class Startup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
ConfigureServices(builder.Services).BuildServiceProvider(true);
}
private IServiceCollection ConfigureServices(IServiceCollection services)
{
return services;
}
}
}
Function.cs;
public class Function1
{
private readonly ILogger<Function1> _logger;
public Function1(ILogger<Function1> logger)
{
_logger = logger;
}
[FunctionName("Function1")]
public async Task Run([ServiceBusTrigger("topic-name", "sb-name", Connection = "AzureServiceBus")]string message)
{
_logger.LogInformation($" HELLO! : {message}");
}
}
CLI和项目配置;
“你好!”就像您在底部日志中看到的那样,正在将其写入CLI!
但是另一个项目缺少HELLO日志,如下所示;
我只是想解决一个错误,该错误会为DI创建竞争条件,从而打破依赖关系。