Skip to content

Instantly share code, notes, and snippets.

@awright18
Last active September 20, 2018 10:20
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 awright18/a09bc2d46a1d5d105cec4526be48cd40 to your computer and use it in GitHub Desktop.
Save awright18/a09bc2d46a1d5d105cec4526be48cd40 to your computer and use it in GitHub Desktop.
Setting Up Serilog with Asp.Net Core
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