Skip to content

Instantly share code, notes, and snippets.

@kentkost
Forked from BryanWilhite/Program.cs
Created May 4, 2022 08:07
Show Gist options
  • Save kentkost/a11fcd185bdf1306f6c1942a3a81dfe3 to your computer and use it in GitHub Desktop.
Save kentkost/a11fcd185bdf1306f6c1942a3a81dfe3 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