Created
May 14, 2021 20:12
-
-
Save manoj-choudhari-git/ef027f8b2cf9af653cc2c717c603f270 to your computer and use it in GitHub Desktop.
.NET Applications - Logging - Set Minimum Log Level in Code
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
class Program | |
{ | |
static Task Main(string[] args) | |
{ | |
var host = CreateHostBuilder(args).Build(); | |
var workerInstance = host.Services.GetRequiredService<Worker>(); | |
workerInstance.Execute(); | |
return host.RunAsync(); | |
} | |
static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureServices((_, services) => | |
{ | |
services.AddTransient<Worker>(); | |
}) | |
.ConfigureLogging((_, logging) => | |
{ | |
logging.SetMinimumLevel(LogLevel.Debug); | |
logging.ClearProviders(); | |
logging.AddSimpleConsole(options => options.IncludeScopes = true); | |
logging.AddEventLog(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment