Where does the ASP.NET Core logging API as default store logs?

后端 未结 2 2137
感情败类
感情败类 2021-01-11 23:31

In the ASP.NET Core 2.0, I use the default logging API. My app is hosted as an Azure Web App.

My question: Where are these outputted? And how do I modify it?

2条回答
  •  情书的邮戳
    2021-01-12 00:15

    You need to add providers as mentioned later in https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?tabs=aspnetcore2x :

    public static void Main(string[] args)
    {
        var webHost = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .ConfigureAppConfiguration((hostingContext, config) =>
            {
                var env = hostingContext.HostingEnvironment;
                config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
                config.AddEnvironmentVariables();
            })
            .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddConsole();
                logging.AddDebug();
            })
            .UseStartup()
            .Build();
    
        webHost.Run();
    }
    

    For azure you can use the Azure App Service provider (https://www.nuget.org/packages/Microsoft.Extensions.Logging.AzureAppServices)

    logging.AddAzureWebAppDiagnostics();
    

提交回复
热议问题