mirror of https://github.com/abpframework/abp
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.
82 lines
2.5 KiB
82 lines
2.5 KiB
using MyCompanyName.MyProjectName.Data;
|
|
using Serilog;
|
|
using Serilog.Events;
|
|
using Volo.Abp.Data;
|
|
|
|
namespace MyCompanyName.MyProjectName;
|
|
|
|
public class Program
|
|
{
|
|
public async static Task<int> Main(string[] args)
|
|
{
|
|
//<TEMPLATE-REMOVE IF-NOT='dbms:PostgreSQL'>
|
|
// https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic
|
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
|
|
|
//</TEMPLATE-REMOVE>
|
|
var loggerConfiguration = new LoggerConfiguration()
|
|
#if DEBUG
|
|
.MinimumLevel.Debug()
|
|
#else
|
|
.MinimumLevel.Information()
|
|
#endif
|
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
|
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
|
|
.Enrich.FromLogContext()
|
|
.WriteTo.Async(c => c.File("Logs/logs.txt"))
|
|
.WriteTo.Async(c => c.Console());
|
|
|
|
if (IsMigrateDatabase(args))
|
|
{
|
|
loggerConfiguration.MinimumLevel.Override("Volo.Abp", LogEventLevel.Warning);
|
|
loggerConfiguration.MinimumLevel.Override("Microsoft", LogEventLevel.Warning);
|
|
}
|
|
|
|
Log.Logger = loggerConfiguration.CreateLogger();
|
|
|
|
try
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
builder.Host.AddAppSettingsSecretsJson()
|
|
.UseAutofac()
|
|
.UseSerilog();
|
|
if (IsMigrateDatabase(args))
|
|
{
|
|
builder.Services.AddDataMigrationEnvironment();
|
|
}
|
|
await builder.AddApplicationAsync<MyProjectNameModule>();
|
|
var app = builder.Build();
|
|
await app.InitializeApplicationAsync();
|
|
|
|
if (IsMigrateDatabase(args))
|
|
{
|
|
await app.Services.GetRequiredService<MyProjectNameDbMigrationService>().MigrateAsync();
|
|
return 0;
|
|
}
|
|
|
|
Log.Information("Starting MyCompanyName.MyProjectName.");
|
|
await app.RunAsync();
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex is HostAbortedException)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
Log.Fatal(ex, "MyCompanyName.MyProjectName terminated unexpectedly!");
|
|
return 1;
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|
|
}
|
|
|
|
private static bool IsMigrateDatabase(string[] args)
|
|
{
|
|
return args.Any(x => x.Contains("--migrate-database", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
}
|