1
1
using System ;
2
- using System . IO ;
3
- using Microsoft . AspNetCore . Hosting ;
2
+ using System . Threading . Tasks ;
3
+ using Microsoft . AspNetCore . Builder ;
4
+ using Microsoft . Extensions . DependencyInjection ;
4
5
using Microsoft . Extensions . Hosting ;
5
6
using Serilog ;
6
7
using Serilog . Events ;
7
8
8
- namespace EasyAbp . CacheManagement
9
+ namespace EasyAbp . CacheManagement ;
10
+
11
+ public class Program
9
12
{
10
- public class Program
13
+ public async static Task < int > Main ( string [ ] args )
11
14
{
12
- public static int Main ( string [ ] args )
13
- {
14
- Log . Logger = new LoggerConfiguration ( )
15
+ Log . Logger = new LoggerConfiguration ( )
15
16
#if DEBUG
16
- . MinimumLevel . Debug ( )
17
+ . MinimumLevel . Debug ( )
17
18
#else
18
- . MinimumLevel . Information ( )
19
+ . MinimumLevel . Information ( )
19
20
#endif
20
- . MinimumLevel . Override ( "Microsoft" , LogEventLevel . Information )
21
- . Enrich . FromLogContext ( )
22
- . WriteTo . File ( "Logs/logs.txt" )
23
- . 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 ( ) ;
24
27
25
- try
26
- {
27
- Log . Information ( "Starting web host." ) ;
28
- CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
29
- return 0 ;
30
- }
31
- catch ( Exception ex )
32
- {
33
- Log . Fatal ( ex , "Host terminated unexpectedly!" ) ;
34
- return 1 ;
35
- }
36
- 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 < CacheManagementHttpApiHostModule > ( ) ;
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 )
37
44
{
38
- Log . CloseAndFlush ( ) ;
45
+ throw ;
39
46
}
40
- }
41
47
42
- internal static IHostBuilder CreateHostBuilder ( string [ ] args ) =>
43
- Host . CreateDefaultBuilder ( args )
44
- . ConfigureWebHostDefaults ( webBuilder =>
45
- {
46
- webBuilder . UseStartup < Startup > ( ) ;
47
- } )
48
- . UseAutofac ( )
49
- . UseSerilog ( ) ;
48
+ Log . Fatal ( ex , "Host terminated unexpectedly!" ) ;
49
+ return 1 ;
50
+ }
51
+ finally
52
+ {
53
+ Log . CloseAndFlush ( ) ;
54
+ }
50
55
}
51
- }
56
+ }
0 commit comments