azureazure-application-insightsazure-monitoringazure-static-web-app

Unable to see my log messages below than Warning on Azure Monitor


I created an Azure Static Web App. I can see the requests of my API functions being executed in application insights (Monitor). But I can't see the log messages below than Warning. In the Azure Function, I'm logging messages as shown below:

        _logger.LogTrace($">>> Log Trace");
        _logger.LogDebug($">>> Log Debug");
        _logger.LogInformation($">>> Log Information");
        _logger.LogWarning($">>> Log Warning");
        _logger.LogError($">>> Log Error");
        _logger.LogCritical($">>> Log Critical");

        Console.WriteLine($">>> Console WriteLine");

As you can see below it is missing Trace Debug Information logging messages.

enter image description here

Below is my .csproj file.

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>
    <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    </ItemGroup>
    <ItemGroup>
    <ProjectReference Include="..\SoutienScolaireV2.Shared\SoutienScolaireV2.Shared.csproj" />
    </ItemGroup>
    <ItemGroup>
    <None Update="Data\database.db">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="host.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
    </ItemGroup>
    <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
    </ItemGroup>
    <ItemGroup>
    <Folder Include="Data\" />
    </ItemGroup>
</Project>

Below is my host.json file.

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "logLevel": {
        "default": "Information",
        "Function": "Information"
      },
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request",
        "logLevel": {
          "default": "Trace"
        }
      },
      "enableLiveMetricsFilters": true
    },
    "logLevel": {
      "default": "Information",
      "Function": "Information"
    }
  }
}

What is missing in order to see all of my logging messages ?


Solution

  • I have tried with your code and done changes in Program.cs file.

     services.Configure<LoggerFilterOptions>(options =>
     {
         LoggerFilterRule logfilter = options.Rules.FirstOrDefault(rule => rule.ProviderName
             == "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
    
         if (logfilter is not null)
         {
             options.Rules.Remove(logfilter);
         }
     });
    

    My Program.cs file:

    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using Microsoft.Extensions.Logging;
    
    var host = new HostBuilder()
        .ConfigureFunctionsWebApplication()
        .ConfigureServices(services =>
        {
            services.AddApplicationInsightsTelemetryWorkerService();
            services.ConfigureFunctionsApplicationInsights();
            services.Configure<LoggerFilterOptions>(options =>
            {
                LoggerFilterRule logfilter = options.Rules.FirstOrDefault(rule => rule.ProviderName
                    == "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
    
                if (logfilter is not null)
                {
                    options.Rules.Remove(logfilter);
                }
            });
        })    
        .Build();
    host.Run();
    

    My host.json file:

    {
      "version": "2.0",
      "logging": {
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Request"
          }
        },
        "logLevel": {
          "default": "Information"
        }
      }
    }
    

    enter image description here

    Refer this SOthread to configure it.

    My .csproj file:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
      <TargetFramework>net8.0</TargetFramework>
      <AzureFunctionsVersion>v4</AzureFunctionsVersion>
      <OutputType>Exe</OutputType>
      <ImplicitUsings>enable</ImplicitUsings>
      <Nullable>enable</Nullable>
      <ApplicationInsightsResourceId>/subscriptions/****/resourceGroups/****/providers/microsoft.insights/components/AppInsights</ApplicationInsightsResourceId>
      <UserSecretsId>****</UserSecretsId>
    </PropertyGroup>
     <ItemGroup>
       <FrameworkReference Include="Microsoft.AspNetCore.App" />
       <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
       <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
       <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
       <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
       <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
       <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
       <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
     </ItemGroup>
        -------
        -------          
    </Project>
    

    Transaction Search: enter image description here

    Logs: enter image description here

    Live Metrics: enter image description here