Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 14, 2021 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/ef027f8b2cf9af653cc2c717c603f270 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/ef027f8b2cf9af653cc2c717c603f270 to your computer and use it in GitHub Desktop.
.NET Applications - Logging - Set Minimum Log Level in Code
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