Last active
December 5, 2021 17:28
-
-
Save jasterix/abb824eaca7cfe7d7cce9b6c54bf82ef to your computer and use it in GitHub Desktop.
Create logs in Main -- The following code logs in Main by getting an ILogger instance from DI after building the host:
This file contains 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 System; | |
using System.Threading.Tasks; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
class Program | |
{ | |
static Task Main(string[] args) | |
{ | |
IHost host = Host.CreateDefaultBuilder(args).Build(); | |
var logger = host.Services.GetRequiredService<ILogger<Program>>(); | |
logger.LogInformation("Host created."); | |
return host.RunAsync(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment