1
- var appName = "Ordering.API" ;
1
+ var appName = "Ordering.API" ;
2
2
var builder = WebApplication . CreateBuilder ( args ) ;
3
- builder . WebHost . ConfigureAppConfiguration ( cb => {
3
+ builder . WebHost . ConfigureAppConfiguration ( cb =>
4
+ {
4
5
var sources = cb . Sources ;
5
- sources . Insert ( 3 , new Microsoft . Extensions . Configuration . Json . JsonConfigurationSource ( ) {
6
+ sources . Insert ( 3 , new Microsoft . Extensions . Configuration . Json . JsonConfigurationSource ( )
7
+ {
6
8
Optional = true ,
7
9
Path = "appsettings.localhost.json" ,
8
10
ReloadOnChange = false
22
24
. AddApplicationServices ( )
23
25
. AddGrpcServices ( ) ;
24
26
var app = builder . Build ( ) ;
25
- if ( app . Environment . IsDevelopment ( ) ) {
27
+ if ( app . Environment . IsDevelopment ( ) )
28
+ {
26
29
app . UseDeveloperExceptionPage ( ) ;
27
30
}
28
- else {
31
+ else
32
+ {
29
33
app . UseExceptionHandler ( "/Home/Error" ) ;
30
34
}
31
35
var pathBase = builder . Configuration [ "PATH_BASE" ] ;
32
- if ( ! string . IsNullOrEmpty ( pathBase ) ) {
36
+ if ( ! string . IsNullOrEmpty ( pathBase ) )
37
+ {
33
38
app . UsePathBase ( pathBase ) ;
34
39
}
35
40
51
56
app . UseAuthorization ( ) ;
52
57
53
58
app . MapDefaultControllerRoute ( ) ;
54
- app . MapControllers ( ) ;
55
- app . MapHealthChecks ( "/hc" , new HealthCheckOptions ( ) {
56
- Predicate = _ => true ,
57
- ResponseWriter = UIResponseWriter . WriteHealthCheckUIResponse
58
- } ) ;
59
- app . MapHealthChecks ( "/liveness" , new HealthCheckOptions {
60
- Predicate = r => r . Name . Contains ( "self" )
61
- } ) ;
59
+ app . MapControllers ( ) ;
60
+ app . MapHealthChecks ( "/hc" , new HealthCheckOptions ( )
61
+ {
62
+ Predicate = _ => true ,
63
+ ResponseWriter = UIResponseWriter . WriteHealthCheckUIResponse
64
+ } ) ;
65
+ app . MapHealthChecks ( "/liveness" , new HealthCheckOptions
66
+ {
67
+ Predicate = r => r . Name . Contains ( "self" )
68
+ } ) ;
62
69
63
- try {
64
-
70
+ try
71
+ {
65
72
Log . Information ( "Starts Web Application ({ApplicationContext})..." , Program . AppName ) ;
66
73
await app . RunAsync ( ) ;
67
74
68
75
return 0 ;
69
76
}
70
- catch ( Exception ex ) {
77
+ catch ( Exception ex )
78
+ {
71
79
Log . Fatal ( ex , "Program terminated unexpectedly ({ApplicationContext})!" , Program . AppName ) ;
72
80
return 1 ;
73
81
}
74
- finally {
82
+ finally
83
+ {
75
84
Log . CloseAndFlush ( ) ;
76
85
}
77
86
78
-
79
- Serilog . ILogger CreateSerilogLogger ( IConfiguration configuration ) {
87
+ Serilog . ILogger CreateSerilogLogger ( IConfiguration configuration )
88
+ {
80
89
var seqServerUrl = configuration [ "Serilog:SeqServerUrl" ] ;
81
90
var logstashUrl = configuration [ "Serilog:LogstashgUrl" ] ;
82
91
return new LoggerConfiguration ( )
@@ -89,7 +98,8 @@ Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) {
89
98
. ReadFrom . Configuration ( configuration )
90
99
. CreateLogger ( ) ;
91
100
}
92
- public partial class Program {
101
+ public partial class Program
102
+ {
93
103
94
104
public static string Namespace = typeof ( Program ) . Assembly . GetName ( ) . Name ;
95
105
public static string AppName = Namespace . Substring ( Namespace . LastIndexOf ( '.' , Namespace . LastIndexOf ( '.' ) - 1 ) + 1 ) ;
@@ -212,4 +222,4 @@ public static IServiceCollection AddGrpcServices(this IServiceCollection service
212
222
213
223
return services ;
214
224
}
215
- }
225
+ }
0 commit comments