-
-
Save kentkost/a11fcd185bdf1306f6c1942a3a81dfe3 to your computer and use it in GitHub Desktop.
.NET Core: using ServiceCollection() and AddConsole() in a console app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using System; | |
namespace Songhay.HelloWorlds.Shell | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var services = new ServiceCollection().AddLogging(builder => | |
{ | |
builder | |
.AddConsole(); | |
}); | |
var serviceProvider = services.BuildServiceProvider(); | |
var logger = serviceProvider.GetRequiredService<ILogger<Program>>(); | |
logger.LogInformation("Hello world!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment