Created
August 30, 2018 04:08
-
-
Save PureKrome/9fa43371509cacff7445add7fe4b3e85 to your computer and use it in GitHub Desktop.
Sample program.cs
This file contains hidden or 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 Microsoft.ApplicationInsights; | |
using Microsoft.AspNetCore; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.Logging; | |
using Serilog; | |
using System; | |
using System.IO; | |
namespace Hornet.Api | |
{ | |
public static class Program | |
{ | |
public static IConfiguration Configuration { get; } = new ConfigurationBuilder() | |
.SetBasePath(Directory.GetCurrentDirectory()) | |
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | |
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true) | |
.AddEnvironmentVariables() | |
.Build(); | |
public static int Main(string[] args) | |
{ | |
Log.Logger = new LoggerConfiguration() | |
.ReadFrom.Configuration(Configuration) | |
.Enrich.FromLogContext() | |
.CreateLogger(); | |
try | |
{ | |
Log.Information($" <::::[]==0 ------------------------------------------ o==[]::::> {Environment.NewLine} *** Starting 'Hornet' web host."); | |
BuildWebHost(args).Run(); | |
return 0; | |
} | |
catch (Exception exception) | |
{ | |
var telemetry = new TelemetryClient(); | |
telemetry.TrackException(exception); | |
Log.Fatal(exception, "Host terminated unexpectedly"); | |
return 1; | |
} | |
finally | |
{ | |
Log.CloseAndFlush(); | |
} | |
} | |
public static IWebHost BuildWebHost(string[] args) => | |
WebHost.CreateDefaultBuilder(args) | |
.UseStartup<Startup>() | |
.UseConfiguration(Configuration) | |
.ConfigureLogging(logger => logger.ClearProviders() | |
.AddSerilog()) | |
.UseApplicationInsights() | |
.SuppressStatusMessages(true) | |
.Build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment