Created
October 23, 2017 19:46
-
-
Save BryanWilhite/d6bb9a5b9bf27343240a8ce815fced9e 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