gpt4 book ai didi

c# - 如何查看 Azure 上的应用程序日志记录

转载 作者:行者123 更新时间:2023-12-01 22:41:34 27 4
gpt4 key购买 nike

我有一个在 azure 上运行的 aspnetcore 2.1 应用程序。

我现在想要查看日志记录信息以调试仅在 Azure 上发生的问题。

在应用程序中,ILogger<>被注入(inject)到类中并使用: this._logger.LogInformation("constructor**********************************************");

如果我在 VS 中运行该应用程序,我可以在调试输出窗口以及 asp.net core Web 服务器输出窗口中看到输出。

然后,我发布并继续到 Azure 并启用日志流并查看它。我确实看到日志流中出现信息,但它只是来自 IIS 的请求信息。我没有看到任何其他日志消息。

我还需要做什么才能查看 Azure 上的日志记录信息吗?

最佳答案

您可以使用Microsoft.Extensions.Logging.AzureAppServices 。该包将自身描述为:

Logger implementation to support Azure App Services 'Diagnostics logs' and 'Log stream' features.

安装该软件包后,您需要更新记录器配置以使用这个新的提供程序,这通常在 Program.cs 中完成,如下所示:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging(loggingBuilder =>
{
loggingBuilder.AddAzureWebAppDiagnostics();
})
...
.UseStartup<Startup>();

关于c# - 如何查看 Azure 上的应用程序日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52578278/

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