1

we are in the process of upgrading some projects to .NET 3.1

I get the following error after changing to 3.1:

'IWebHostEnvironment' does not contain a definition for 'ConfigureNLog' and the best extension method overload 'AspNetExtensions.ConfigureNLog(ILoggingBuilder, string)' requires a receiver of type 'ILoggingBuilder'

This is the code:

        public static async Task Main(string[] args)
        {
            var builder = new WebHostBuilder();


            var config = configurationBuilder.Build();

            // it is possible to override the config file with command line arguments
            var webHostBuilder = WebHost.CreateDefaultBuilder(args)
                .UseConfiguration(config)
                .ConfigureLogging((context, loggingBuilder) =>
                {
                    if (File.Exists(".\\NLog.config"))
                    {
                        context.HostingEnvironment.ConfigureNLog(".\\NLog.config");
                    }
                    loggingBuilder.SetMinimumLevel(LogLevel.Trace);
                })
                .UseNLog()
                .UseStartup<Startup>();

            var webHost = webHostBuilder.Build();

            await webHost.RunAsync().ConfigureAwait(false);
        }

The line that breaks the code is:

context.HostingEnvironment.ConfigureNLog(".\\NLog.config");

we've updated our NLog to the latest version (4.14.0) I tried to install NLog.Extensions.Logging package (version 1.7.1)

I looked in NLog GitHub for some guides but could not find anything

Any help would be appreciated

Amir Dar
  • 35
  • 5
  • Does this answer your question? [Use NLog in ASP.NET Core application](https://stackoverflow.com/questions/34679727/use-nlog-in-asp-net-core-application). See" ASP.NET Core 3 & 5. There are some small changes compared to ASP.NET Core 2, e.g. there is an IHostBuilder instead of the IWebHostBuilder." – Julian Apr 18 '22 at 09:31
  • NLog will usually load the `NLog.config` without needing extra help. Think you should just remove `File.Exists(".\\NLog.config")` and `ConfigureNLog(".\\NLog.config")`. – Rolf Kristensen Apr 18 '22 at 16:19

0 Answers0