You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
using System;
|
|
using System.IO;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Serilog;
|
|
using Serilog.Events;
|
|
using Serilog.Sinks.Elasticsearch;
|
|
|
|
namespace BaseService
|
|
{
|
|
public class Program
|
|
{
|
|
public static int Main(string[] args)
|
|
{
|
|
var configuration = new ConfigurationBuilder()
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("appsettings.json")
|
|
.AddEnvironmentVariables()
|
|
.Build();
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
.MinimumLevel.Debug()
|
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
|
.Enrich.WithProperty("Application", "BaseService")
|
|
.Enrich.FromLogContext()
|
|
.WriteTo.File("Logs/logs.txt")
|
|
.WriteTo.Console()
|
|
.CreateLogger();
|
|
|
|
try
|
|
{
|
|
Log.Information("Starting BaseService.Host.");
|
|
CreateHostBuilder(args).Build().Run();
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Fatal(ex, "BaseService.Host terminated unexpectedly!");
|
|
return 1;
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|
|
}
|
|
|
|
internal static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
})
|
|
.UseAutofac()
|
|
.UseSerilog();
|
|
}
|
|
}
|
|
|