Skip to content

Instantly share code, notes, and snippets.

@BryanWilhite
Created October 23, 2017 19:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BryanWilhite/d6bb9a5b9bf27343240a8ce815fced9e to your computer and use it in GitHub Desktop.
Save BryanWilhite/d6bb9a5b9bf27343240a8ce815fced9e to your computer and use it in GitHub Desktop.
.NET Core: using ServiceCollection() and AddConsole() in a console app
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