如何在ASP.NET Core 3.0中禁用默认日志记录

时间:2019-10-09 01:57:37

标签: c# asp.net-core asp.net-core-3.0

在asp.net core 2.2中,我可以使用ClearProviders禁用默认日志记录,如下代码:

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

但是我在asp.net core 3.0中找不到ClearProviders
如何在asp.net core 3.0中做到这一点?

2 个答案:

答案 0 :(得分:4)

根据documentation,ASP.NET Core 3.0支持ClearProviders()。 也许您很想念using Microsoft.Extensions.Logging;

答案 1 :(得分:0)

尝试将IWebHostBuilder更改为IHostBuilder。还要将WebHost更改为主机

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
    .ConfigureLogging((logging) =>
    {
        // clear default logging providers
        logging.ClearProviders();
    })
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.UseStartup<Startup>();
    });