IWebHostBuilder doesn't contain definition for UseNLog()

See original GitHub issue

I’m using the latest version of Nlog.Web.AspNetcore (4.5.0-rc3) but can’t use the UseNLog method.

As a workaround I had to update my Startup.cs with the following to add NLog to the configuration:

public void Configure(IApplicationBuilder app, 
    IHostingEnvironment env,
    ILoggerFactory loggerFactory)
{
    ...

    loggerFactory.AddNLog();
    app.AddNLogWeb();

    ...
}

And in my Program.cs

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()            
        .ConfigureLogging((host, logging) =>
        {
            // Clear providers so logs don't get written to console
            logging.ClearProviders();
            host.HostingEnvironment.ConfigureNLog("nlog.config");
        })
        .Build();

This gets everything working but I’m getting an obsolete warning

Startup.cs(38,13): warning CS0618: 'AspNetExtensions.AddNLogWeb(IApplicationBuilder)' is obsolete: 
'Use UseNLog() on IWebHostBuilder'

Is there something I’m missing here?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
snakefootcommented, Mar 6, 2018

@devon-stanley Do you have this in top of your Program.cs ?

using NLog.Web;

See also https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2#4-update-programcs

3reactions
devon-stanleycommented, Mar 7, 2018

So I’m not sure what was wrong with my local environment, but I was finally able get UseNLog() and LoadConfiguration working by:

  1. Explicitly referencing NLog in the .csproj file by adding <PackageReference Include="NLog" Version="4.5.0-rc06" />
  2. Clearing my nuget packages with dotnet nuget locals --clear all
  3. Restore my dependencies dotnet restore

Thanks @snakefoot , @304NotModified and @BlueInt32 for the pointers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use NLog in ASP.NET Core application
I found a CodeProject with an example of how to get this to work, but it doesn't work. The main problem seems to...
Read more >
error CS1929: 'ConfigureHostBuilder' does not contain a ...
Hi Team, I am trying to use Serilog for capturing logs for my Opentelemetry. When I am using Web App console example into...
Read more >
[Solved]-Use NLog in ASP.NET Core application-.net-core
For ASP.NET Core, you need NLog.Web.AspNetCore - which has a dependency on NLog.Extensions.Logging. Note: Microsoft.Framework.Logging.NLog has been replaced by ...
Read more >
How to use NLog with ASP.NET Core 2
The file format can be defined using the layout attribute in a target element. NLog is easy to use and configure with ASP.NET...
Read more >
ASP.NET Core: Logging file using NLog
This post shows you How to integrate logging using NLog in ASP. ... ILoggingBuilder' does not contain a definition for 'AddNLog' and no ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found