-
Notifications
You must be signed in to change notification settings - Fork 199
Description
What version of .NET does your existing project use?
.NET 6
What version of .NET are you attempting to target?
.NET 6
Description
Upgrading azure function in-process model into isolated model. Followed the steps mentioned [here](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=windows#logging)
When running the function locally, I can see the logs reaching Application Insight, but after deploying it into azure I don't see logs reaching Application Insight, neither in Log Stream.
When working locally, I imported application settings from deployed function app in azure. I am sure that APPINSIGHTS_INSTRUMENTATIONKEY & APPLICATIONINSIGHTS_CONNECTION_STRING are correct.
I tried using Serilog for writing logs into Application Insight using Serilog.Sinks.ApplicationInsights (4.0.0) but the result is same as above.
Used both approaches for obtaining logger instance: Using dependency insjection & via FuctionContext.GetLogger(categoryName) method.
My question is: If function is generating logs when ran locally, then why is it not working as expected in azure?
Is the worker process not communicating with host? Is there any other unknown configuration which is overriding my code?
Do we have to define log level for the categaoryName parameter passed into FuctionContext.GetLogger(categoryName) host.json?
Below is the snippet from startup class.
string appInsightConnectionString = "<application insight connection string>";
var host = new HostBuilder()
.ConfigureServices((context, services) =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
services.AddLogging(builder =>{
builder.AddApplicationInsights(
telemetryConfig => {telemetryConfig.ConnectionString = appInsightConnectionString;},
loggerOptions =>{loggerOptions.FlushOnDispose = true;});
});
})
.ConfigureLogging(logging =>
{
logging.Services.Configure<LoggerFilterOptions>(options =>
{
LoggerFilterRule defaultRule = options.Rules.FirstOrDefault(rule => rule.ProviderName
== "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
if (defaultRule is not null)
{
options.Rules.Remove(defaultRule);
}
options.MinLevel = LogLevel.Information;
});
})
.Build();
await host.RunAsync();
host.json
{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Information",
"Function": "Information",
"Host.Result": "Information",
"Host.Aggregator": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": false,
"excludedTypes": "Request;Exception;Trace"
},
"httpAutoCollectionOptions": {
"enableHttpTriggerExtendedInfoCollection": false,
"enableW3CDistributedTracing": true
}
},
"extensions": {
"durableTask": {
"maxConcurrentActivityFunctions": 1000,
"maxConcurrentOrchestratorFunctions": 100
}
}
}
}
Links referred:
#1123
#944
#702
#760
#1123
Project configuration and dependencies
Startup project .csproj file content
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64</RuntimeIdentifiers>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.17.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.6" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.35.0" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
<None Update="local.settings.arc.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Link to a repository that reproduces the issue
No response