Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.ApplicationInsights;
using Notifier.Common.Extensions;
using Notifier.Common.Settings;
namespace Notifier.WebApi
{
class Program
{
static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostBuilderContext, builder) =>
{
// Add configuration file, environment variables and command line arguments
builder
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.AddCommandLine(args);
// Add user secrets from this assembly and key vault if there is set one
builder
.AddUserSecrets(typeof(Program).Assembly, false)
.AddAzureKeyVault();
})
.ConfigureLogging((context, builder) =>
{
builder.AddConfiguration(context.Configuration.GetSection(nameof(LoggingSettings)));
builder.AddConsole();
builder.AddFilter<ApplicationInsightsLoggerProvider>(
"",
Microsoft.Extensions.Logging.LogLevel.Information); // this will capture Info level traces and above.
})
.ConfigureWebHostDefaults(webBuilder =>
{
// Configure kestrel web server and call startup.
webBuilder
.ConfigureKestrel(serverOptions =>
{
// Needed because of using newtonsoft json
// (else there are performance issues in .net core 3)
serverOptions.AllowSynchronousIO = true;
})
.UseStartup<Startup>();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment