dev-masih
dev-masih

Reputation: 4746

How to disable default logging in ASP.NET Core 3.0

In asp.net core 2.2 I could disable default logging with ClearProviders like in this code:

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

but I can't find ClearProviders in asp.net core 3.0
how can I do this in asp.net core 3.0?

Upvotes: 1

Views: 6159

Answers (3)

oznakdn
oznakdn

Reputation: 1

You should write this code in program.cs builder.Logging.ClearProviders();

Upvotes: 0

brian
brian

Reputation: 692

Try changing the IWebHostBuilder to IHostBuilder. Also Change WebHost to Host

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>();
    });

Upvotes: 1

Anna
Anna

Reputation: 3256

The ClearProviders() is supported in ASP.NET Core 3.0 as per documentation. Maybe you miss using Microsoft.Extensions.Logging; by any chance.

Upvotes: 11

Related Questions