Skip to content

Commit e993be9

Browse files
committed
Remove Startup.cs
1 parent ef79f8b commit e993be9

File tree

2 files changed

+41
-62
lines changed

2 files changed

+41
-62
lines changed
Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,56 @@
11
using System;
2-
using Microsoft.AspNetCore.Hosting;
3-
using Microsoft.Extensions.Configuration;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.Extensions.DependencyInjection;
45
using Microsoft.Extensions.Hosting;
56
using Serilog;
67
using Serilog.Events;
78

8-
namespace DynamicEntitySample.Web
9+
namespace DynamicEntitySample.Web;
10+
11+
public class Program
912
{
10-
public class Program
13+
public async static Task<int> Main(string[] args)
1114
{
12-
public static int Main(string[] args)
13-
{
14-
Log.Logger = new LoggerConfiguration()
15+
Log.Logger = new LoggerConfiguration()
1516
#if DEBUG
16-
.MinimumLevel.Debug()
17+
.MinimumLevel.Debug()
1718
#else
18-
.MinimumLevel.Information()
19+
.MinimumLevel.Information()
1920
#endif
20-
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
21-
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
22-
.Enrich.FromLogContext()
23-
.WriteTo.Async(c => c.File("Logs/logs.txt"))
24-
#if DEBUG
25-
.WriteTo.Async(c => c.Console())
26-
#endif
27-
.CreateLogger();
21+
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
22+
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
23+
.Enrich.FromLogContext()
24+
.WriteTo.Async(c => c.File("Logs/logs.txt"))
25+
.WriteTo.Async(c => c.Console())
26+
.CreateLogger();
2827

29-
try
30-
{
31-
Log.Information("Starting web host.");
32-
CreateHostBuilder(args).Build().Run();
33-
return 0;
34-
}
35-
catch (Exception ex)
36-
{
37-
Log.Fatal(ex, "Host terminated unexpectedly!");
38-
return 1;
39-
}
40-
finally
28+
try
29+
{
30+
Log.Information("Starting web host.");
31+
var builder = WebApplication.CreateBuilder(args);
32+
builder.Host.AddAppSettingsSecretsJson()
33+
.UseAutofac()
34+
.UseSerilog();
35+
await builder.AddApplicationAsync<DynamicEntitySampleWebModule>();
36+
var app = builder.Build();
37+
await app.InitializeApplicationAsync();
38+
await app.RunAsync();
39+
return 0;
40+
}
41+
catch (Exception ex)
42+
{
43+
if (ex is HostAbortedException)
4144
{
42-
Log.CloseAndFlush();
45+
throw;
4346
}
44-
}
4547

46-
internal static IHostBuilder CreateHostBuilder(string[] args) =>
47-
Host.CreateDefaultBuilder(args)
48-
.ConfigureAppConfiguration(build =>
49-
{
50-
build.AddJsonFile("appsettings.secrets.json", optional: true);
51-
})
52-
.ConfigureWebHostDefaults(webBuilder =>
53-
{
54-
webBuilder.UseStartup<Startup>();
55-
})
56-
.UseAutofac()
57-
.UseSerilog();
48+
Log.Fatal(ex, "Host terminated unexpectedly!");
49+
return 1;
50+
}
51+
finally
52+
{
53+
Log.CloseAndFlush();
54+
}
5855
}
59-
}
56+
}

sample/aspnet-core/src/DynamicEntitySample.Web/Startup.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)