Configuring Logger in Razor Pages application

2.9k views Asked by At

I'm trying to get up to speed on ASP.NET Core Razor Pages so I was trying to step through the article Logging in .NET Core and ASP.NET Core.

A lot of the documentation I've been finding is not panning out for one reason or another, and I didn't get very far through this article either. Near the top, it contains the following code snippet.

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

But that code just won't even compile for me.

enter image description here

I've tried Ctrl+. and everything else I could think of, but WebHostBuilderContext just doesn't have the methods shown in this article.

Can someone tell me what I'm doing wrong?

1

There are 1 answers

3
Davide Piras On BEST ANSWER

Assuming you are also using .NET Core 3,

the sample works for me out of the box with no issues if i create a new ASP.NET Core MVC app in VS 2019 selecting .NET Core 3,

you might not have created a project in that way, are you sure you have this using at the top? if not, add this at top of program.cs and if does not resolve means you have to first add the reference to this assembly.

using Microsoft.Extensions.Logging;