Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'ILoggingBuilder' does not contain a definition for 'AddFile'

ILoggingBuilder' does not contain a definition for 'AddFile' and the best extension method overload 'FileLoggerExtensions.AddFile(ILoggerFactory, IConfigurationSection)' requires a receiver type of 'ILoggerFactory'

Note the line in the code marked with <== Exception.

According to everything I can find online this should work, but I get the error above.

I can't find anything to suggest what the problem is.

Probably something daft. Any suggestions gratefully received!

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace my.namespace
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureLogging(logging =>
                {
                    logging.ClearProviders();
                    logging.AddFile("..."); // <== Exception
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}
like image 804
CompanyDroneFromSector7G Avatar asked Oct 07 '19 15:10

CompanyDroneFromSector7G


People also ask

Is it possible to add a file using the 'iloggingbuilder' extension?

ILoggingBuilder' does not contain a definition for 'AddFile' and the best extension method overload 'FileLoggerExtensions.AddFile (ILoggerFactory, IConfigurationSection)' requires a receiver type of 'ILoggerFactory' Note the line in the code marked with <== Exception.

Is it possible to add a console in the iloggerfactory?

'ILoggerFactory' does not contain a definition for 'AddConsole' and the best extension method overload 'ConsoleLoggerExtensions.AddConsole (ILoggingBuilder)' requires a receiver of type 'ILoggingBuilder' I'm using NET Core 3.0 and I have the following NuGet packages installed.

Does'iloggerfactory'contain a definition for'addconsole (iloggingbuilder)'?

It gives the following error: 'ILoggerFactory' does not contain a definition for 'AddConsole' and the best extension method overload 'ConsoleLoggerExtensions.AddConsole (ILoggingBuilder)' requires a receiver of type 'ILoggingBuilder' I'm using NET Core 3.0 and I have the following NuGet packages installed.

How to add 'addlog4net' to 'iloggerfactory'?

‘ILoggerFactory’ does not contain a definition for ‘AddLog4Net’ and no accessible extension method ‘AddLog4Net’ accepting a first argument of type ‘ILoggerFactory’ could be found (are you missing a using directive or an assembly reference?) Run this NUGET Command from the Package Manager Console in Visual Studio.


Video Answer


1 Answers

Found the answer. I was using an earlier version of the package.

The one I needed was still a dev version, although dated 2018.

> Install-Package Serilog.Extensions.Logging.File -Version 2.0.0-dev-00024

like image 128
CompanyDroneFromSector7G Avatar answered Oct 21 '22 09:10

CompanyDroneFromSector7G