Last active
September 20, 2018 10:20
-
-
Save awright18/a09bc2d46a1d5d105cec4526be48cd40 to your computer and use it in GitHub Desktop.
Setting Up Serilog with Asp.Net Core
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
public class Program | |
{ | |
public IConfiguration Configuration = | |
new ConfigurationBuilder() | |
.AddJsonFile("appSettings.json") | |
.AddEnvironmentVariables() | |
.AddUserSecrets<StartUp>(); | |
public static Task<int> Main(string[] args) | |
{ | |
Log.Logger = new LoggerConfiguration() | |
.ReadFrom.Configuration(Configuration.GetSection("Serilog")) | |
.CreateLogger(); | |
try | |
{ | |
Log.Information("Starting web host"); | |
BuildWebHost(args).Run(); | |
return 0; | |
} | |
catch (Exception ex) | |
{ | |
Log.Fatal(ex, "Host terminated unexpectedly"); | |
return 1; | |
} | |
finally | |
{ | |
Log.CloseAndFlush(); | |
} | |
} | |
public static IWebHost BuildWebHost(string[] args) => | |
WebHost.CreateDefaultBuilder(args) | |
.UseStartup<Startup>() | |
.UseSerilog() | |
.Build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment