IWebHostBuilder doesn't contain definition for UseNLog()
See original GitHub issueI’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:
- Created 6 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
So I’m not sure what was wrong with my local environment, but I was finally able get
UseNLog()andLoadConfigurationworking by:<PackageReference Include="NLog" Version="4.5.0-rc06" />dotnet nuget locals --clear alldotnet restoreThanks @snakefoot , @304NotModified and @BlueInt32 for the pointers!