gpt4 book ai didi

azure - ASP.NET Core 3.1 无法在 Azure 服务日志流上查看我的日志

转载 作者:行者123 更新时间:2023-12-03 00:56:58 27 4
gpt4 key购买 nike

以下是我的配置方法:

1.安装nuget包Microsoft.Extensions.Logging.AzureAppServices,版本3.1.2和Microsoft.Extensions.Logging.Console,版本3.1.2

我在 azure 中启用了应用程序日志记录

在program.cs中

 public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureLogging(logging =>
{
logging.ClearProviders();
// We have to be precise on the logging levels
logging.AddConsole();
logging.AddDebug();
logging.AddAzureWebAppDiagnostics();
})
.ConfigureWebHostDefaults(builder =>
{
builder.ConfigureAppConfiguration((builderContext, config) =>
{
var env = builderContext.HostingEnvironment;

builder.UseStartup<Startup>()

.UseSerilog(); ;
}).ConfigureServices(services =>
{

services.Configure<AzureFileLoggerOptions>(options =>
{
options.FileName = "my-azure-diagnostics-";
options.FileSizeLimit = 50 * 1024;
options.RetainedFileCountLimit = 5;
});
}); ;
}

在startup.cs中的ConfigureServices方法中

 // Logging
services.AddLogging(builder => builder
.AddConsole()
.AddDebug()
.AddAzureWebAppDiagnostics()
.AddApplicationInsights())

// .AddConfiguration(Configuration.GetSection("Logging")))
;

我添加了日志消息

    _logger.LogDebug("DEBUG message. GET enpoint was called.");

但我看不到我的日志,我缺少什么?

最佳答案

我在这里展示了适合我的代码。请部署,如果不起作用,则应用服务日志配置不正确

引用Microsoft.Extensions.Logging (5.0.0),Microsoft.Extensions.Logging.AzureAppServices(5.0.3)

在Program.cs中

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
logging.AddDebug();
logging.AddAzureWebAppDiagnostics();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});

在 Startup.cs 中

public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();

}

在appsettings.json

{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

在index.cshtml.cs中

public void OnGet()
{
_logger.LogInformation($"Logging {DateTime.Now.ToLongTimeString()}");
}

门户中的配置

enter image description here

关于azure - ASP.NET Core 3.1 无法在 Azure 服务日志流上查看我的日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66365192/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com