I use Serilog for logging in most of my console applications as specified here, however the AddConsole and AddDebug extension methods are now obsolete in .NET Core 2.2 giving the below errors.

‘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. The recommended alternative is AddDebug(this ILoggingBuilder builder).’

serviceCollection.AddSingleton(new LoggerFactory()
	.AddConsole()
	.AddSerilog()
	.AddDebug());
serviceCollection.AddLogging();

After a bit of research it turns out I just needed to make use of the ILoggingBuilder constructor accessible through the AddLogging method of the service collection.

serviceCollection.AddLogging(loggingBuilder =>
{
	loggingBuilder.AddConsole();
	loggingBuilder.AddSerilog();
	loggingBuilder.AddDebug();
});

Derek Broughton · 8th May 2019 at 2:38 pm

Thanks so much. As usual, Microsoft’s error message leaves an awful log up to your imagination!

Leave a Reply

Your email address will not be published. Required fields are marked *