Skip to content

Instantly share code, notes, and snippets.

@screamingworld
Last active February 28, 2021 23:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save screamingworld/33b29f558c37224f436f2887a2dfa797 to your computer and use it in GitHub Desktop.
using System.Net;
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
{
public class Program
{
public 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)
.AddUserSecrets(typeof(Program).Assembly, false)
.AddEnvironmentVariables()
.AddCommandLine(args);
})
.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 =>
{
serverOptions.Listen(IPAddress.Any, 8080);
// 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