Created
August 10, 2019 14:38
-
-
Save JordiCorbilla/21f192c97b877f2b462c6675500484a7 to your computer and use it in GitHub Desktop.
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.AspNetCore; | |
using Microsoft.AspNetCore.Hosting; | |
using Serilog; | |
using Serilog.Events; | |
using System; | |
namespace test | |
{ | |
public class Program | |
{ | |
public static int Main(string[] args) | |
{ | |
//Specify the template to use via Console | |
Log.Logger = new LoggerConfiguration() | |
.MinimumLevel.Debug() | |
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) | |
.Enrich.FromLogContext() | |
.WriteTo.Console(outputTemplate: "[{Timestamp:yyyy-MMM-dd HH:mm:ss.fff}] [{Level}] {Message}{NewLine}{Exception}") | |
.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(); | |
} | |
} | |
//Use serilog here | |
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