Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement