小编Mic*_*ski的帖子

如何为 ASP.NET Core 应用程序配置 Azure 应用服务日志记录提供程序?

我正在尝试在 ASP.NET Core MVC 应用程序中配置自定义日志记录。该应用托管在 Linux 上的 Azure 应用服务(免费套餐)上。日志文件没有出现,我做错了什么?

我的配置:

在 ASP.NET Core 日志记录文档(https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1#azure-app-service-provider)之后,我添加了我的应用程序的 Azure 应用服务日志记录提供程序:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureLogging(logging =>
                {
                    logging.ClearProviders();
                    logging.AddAzureWebAppDiagnostics();
                })
                .ConfigureServices(serviceCollection => serviceCollection
                    .Configure<AzureFileLoggerOptions>(options =>
                    {
                        options.FileName = "azure-diagnostics-";
                        options.FileSizeLimit = 10 * 1024;
                        options.RetainedFileCountLimit = 5;
                    })
                )
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseUrls("http://*:8080");
                    webBuilder.UseStartup<Startup>();
                });
Run Code Online (Sandbox Code Playgroud)

app.settings 中的日志配置:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}
Run Code Online (Sandbox Code Playgroud)

我正在控制器中记录信息、警告和错误。

按照Azure文档(https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs#enable-application-logging-linuxcontainer),我已在Azure上启用了对文件系统的日志记录应用程序 -> 应用程序服务日志: …

c# azure azure-web-app-service asp.net-core

6
推荐指数
1
解决办法
4949
查看次数

标签 统计

asp.net-core ×1

azure ×1

azure-web-app-service ×1

c# ×1