-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
62 deletions.
There are no files selected for viewing
85 changes: 41 additions & 44 deletions
85
sample/aspnet-core/src/DynamicEntitySample.Web/Program.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,56 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Serilog; | ||
using Serilog.Events; | ||
|
||
namespace DynamicEntitySample.Web | ||
namespace DynamicEntitySample.Web; | ||
|
||
public class Program | ||
{ | ||
public class Program | ||
public async static Task<int> Main(string[] args) | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
Log.Logger = new LoggerConfiguration() | ||
#if DEBUG | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Debug() | ||
#else | ||
.MinimumLevel.Information() | ||
.MinimumLevel.Information() | ||
#endif | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) | ||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Async(c => c.File("Logs/logs.txt")) | ||
#if DEBUG | ||
.WriteTo.Async(c => c.Console()) | ||
#endif | ||
.CreateLogger(); | ||
.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()) | ||
.CreateLogger(); | ||
|
||
try | ||
{ | ||
Log.Information("Starting web host."); | ||
CreateHostBuilder(args).Build().Run(); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Host terminated unexpectedly!"); | ||
return 1; | ||
} | ||
finally | ||
try | ||
{ | ||
Log.Information("Starting web host."); | ||
var builder = WebApplication.CreateBuilder(args); | ||
builder.Host.AddAppSettingsSecretsJson() | ||
.UseAutofac() | ||
.UseSerilog(); | ||
await builder.AddApplicationAsync<DynamicEntitySampleWebModule>(); | ||
var app = builder.Build(); | ||
await app.InitializeApplicationAsync(); | ||
await app.RunAsync(); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (ex is HostAbortedException) | ||
{ | ||
Log.CloseAndFlush(); | ||
throw; | ||
} | ||
} | ||
|
||
internal static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration(build => | ||
{ | ||
build.AddJsonFile("appsettings.secrets.json", optional: true); | ||
}) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}) | ||
.UseAutofac() | ||
.UseSerilog(); | ||
Log.Fatal(ex, "Host terminated unexpectedly!"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.