Skip to content

Instantly share code, notes, and snippets.

@JordiCorbilla
Created August 10, 2019 14:38
Show Gist options
  • Save JordiCorbilla/21f192c97b877f2b462c6675500484a7 to your computer and use it in GitHub Desktop.
Save JordiCorbilla/21f192c97b877f2b462c6675500484a7 to your computer and use it in GitHub Desktop.
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