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

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 =>


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!

Dasith · 2nd August 2019 at 4:24 am

You can also follow this method if you want to instantiate it outside of the DI.
`var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole())`

    Shinigami · 2nd August 2019 at 10:47 am

    Thanks, hadn’t seen that documentation before. Looks like it’s going to change again for 3.0.

Leave a Reply to D S WijesiriwardenaDasith Cancel reply

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

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://dc.services.visualstudio.com/v2/track` resulted in a `400 Invalid instrumentation key` response: {"itemsReceived":1,"itemsAccepted":0,"errors":[{"index":0,"statusCode":400,"message":"Invalid instrumentation key"}]} in D:\home\site\wwwroot\wp-content\plugins\application-insights\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113 Stack trace: #0 D:\home\site\wwwroot\wp-content\plugins\application-insights\vendor\guzzlehttp\guzzle\src\Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 D:\home\site\wwwroot\wp-content\plugins\application-insights\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response)) #2 D:\home\site\wwwroot\wp-content\plugins\application-insights\vendor\guzzlehttp\promises\src\Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\P in D:\home\site\wwwroot\wp-content\plugins\application-insights\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113