azure - Microsoft.Extensions.Logging.AzureAppServices 未显示在 Azure 日志流中

标签 azure asp.net-core logging azure-web-app-service azure-app-service-envrmnt

我觉得我已经尝试了所有方法来获取 Azure 门户中显示的日志消息。

我已经在我的项目中安装了相关的NuGet包:

Microsoft.ApplicationInsights.AspNetCore

我已在 Azure 门户中启用日志记录。

enter image description here

我已将以下内容添加到我的 appsettings.json 中:

"AzureLogging": {
    "FileName": "azure-diagnostics-",
    "FileSizeLimit": 50024,
    "RetainedFileCountLimit": 5
  }

并在Startup中添加以下设置代码,以确保它已添加其中之一。

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

我能从日志中得到的唯一信息如下:

enter image description here

最佳答案

在 Startup.cs -> 配置方法中,您应该添加以下代码行:

loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddConsole();

这是我的Startup.cs中的Configure方法的代码:

        public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            //add the following 2 lines of code.
            loggerFactory.AddAzureWebAppDiagnostics();
            loggerFactory.AddConsole();


            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }

发布到azure后 -> 启用应用程序日志记录(文件系统),然后在日志流中,我可以看到日志的输出(我在测试中将日志级别设置为详细):

enter image description here

关于azure - Microsoft.Extensions.Logging.AzureAppServices 未显示在 Azure 日志流中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58269169/

相关文章:

Azure AD ADAuthenticationError 15-unauthorized_client-此 API 版本不支持应用程序

C# 上下文已经在跟踪实体、azure Active Directory 图形 api。添加群组成员

c# - 在 .net 核心项目中按环境加载 WCF 服务

asp.net - 授权与 Active Directory .NET Core 1.1、.Net Framework 的属性交互

Linux grep 和排序日志文件

python - 将自定义格式化程序类与 Python 的 logging.config 模块一起使用

sql-server - 是否可以将 SQL Server session 上下文与 Azure 弹性查询一起使用

c# - 异步计时问题

logging - 在 Mule ESB 中监控或记录消息

json - Azure 网站实例未运行 Package.json 中定义的 Node 版本