如何配置Azure Web App日志记录设置

时间:2018-10-31 14:08:35

标签: asp.net azure logging

我的Asp.Net Core API应用托管在Azure上。当将选项Azure > Diagnostic logs > Application Logging (Filesystem) > Level设置为Information时,可以在日志流中看到控制器和Entity Framework信息日志,包括SQL查询。我尝试了appsettings.json

{ "Logging": {
        "LogLevel": {
            "Default": "None",
            "System": "None",
            "Microsoft": "None"
        },

        "IncludeScopes": false,
        "Debug": {
            "LogLevel": {
                "Default": "Warning",
                "Microsoft": "None",
                "Microsoft.EntityFrameworkCore": "None"
            }
        },
        "Console": {
            "LogLevel": {
                "Default": "Warning",
                "Microsoft": "None",
                "Microsoft.EntityFrameworkCore": "None"
            }
        }

    }
}

和Program.cs:

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .ConfigureLogging((hostingContext, logging) =>
                {
                    logging.SetMinimumLevel(LogLevel.Warning);
                    logging.AddAzureWebAppDiagnostics();
                    logging.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Error);
                })
                .UseStartup<Startup>()
                .Build();

0 个答案:

没有答案