private ILoggerFactory ConfigureLogging(ILoggerFactory factory) { factory.AddConsole(); return factory; }
I have found the piece of code above on Github. 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.
<PackageReference Include="Discord.Net" Version="2.1.1" /> <PackageReference Include="Discord.Net.Commands" Version="2.1.1" /> <PackageReference Include="Discord.Net.WebSocket" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" /> <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.0" />
Why do I get that ILoggerFactory
does not have the method AddConsole()
? How can I fix this?
'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.
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.
‘ConsoleLoggerExtensions.AddConsole (ILoggerFactory)’ is obsolete: ‘This method is obsolete and will be removed in a future version. The recommended alternative is AddConsole (this ILoggingBuilder builder).’ ‘ConsoleLoggerExtensions.AddDebug (ILoggerFactory)’ is obsolete: ‘This method is obsolete and will be removed in a future version.
‘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.
I just ran into this following a course on Pluralsight. I got ahead of myself before the next slide explaining why their .AddConsole was working in the ILoggerFactory.Create.
Even though you only need using Microsoft.Extensions.Logging
in your class, you need to explicitly add a package reference to your .Net Core app in order for the .AddConsole method to be found.
dotnet add package Microsoft.Extensions.Logging.Console
and add this using statement to your code
using Microsoft.Extensions.Logging;
There is a seperate issue at play, previously the signature for AddConsole() expected an ILoggerFactory, that has since changed to an ILoggerBuilder, as hinted at in the error message.
The following it seems is the new way to stand up a new Console logger:
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With