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();
});

0 Comments

Leave a Reply

Avatar placeholder

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