在 Azure Monitor 上无法看到下面的警告消息

问题描述 投票:0回答:1

我创建了一个 Azure 静态 Web 应用程序。我可以在应用程序洞察(监视器)中看到正在执行的 API 函数的请求。但我看不到下面的日志消息

Warning
。在 Azure 函数中,我正在记录消息,如下所示:

        _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");

正如您在下面看到的,它缺少

Trace
Debug
Information
日志消息。

enter image description here

下面是我的 .csproj 文件。

<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>

下面是我的 host.json 文件。

{
  "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"
    }
  }
}

为了查看我的所有日志消息,缺少什么?

azure azure-application-insights azure-monitoring azure-static-web-app
1个回答
0
投票

我已部署您的代码并在

Program.cs
文件中进行了更改。

 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);
     }
 });
  • 现在我可以看到日志信息跟踪以及其他严重级别。

我的

Program.cs
文件:

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();
  • 我也可以使用以下配置使用默认代码记录所有跟踪。

我的

host.json
文件:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
      "default": "Information"
    }
  }
}
  • 当我们创建 Function App 时,最初将 Application Insights 配置为本地。
  • 断开连接并将其更改为
    Azure Application Insights

enter image description here

参考这个SOthread来配置它。

我的

.csproj
文件:

<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>

交易搜索: enter image description here

日志: enter image description here

实时指标: enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.