44using System . Threading . Tasks ;
55using Microsoft . AspNetCore . Hosting ;
66using Serilog ;
7+ using Serilog . Events ;
78using SqlStreamStore . HAL ;
9+ using static SqlStreamStore . Server . Constants ;
810
911namespace SqlStreamStore . Server
1012{
11- internal class Program : IDisposable
13+ internal class SqlStreamStoreServer : IDisposable
1214 {
15+ private static readonly ILogger s_Log = Log . ForContext < SqlStreamStoreServer > ( ) ;
16+
1317 private readonly CancellationTokenSource _cts ;
1418 private readonly SqlStreamStoreServerConfiguration _configuration ;
1519 private readonly SqlStreamStoreFactory _factory ;
@@ -20,21 +24,52 @@ public static async Task<int> Main(string[] args)
2024 Environment . GetEnvironmentVariables ( ) ,
2125 args ) ;
2226
23- using ( var program = new Program ( configuration ) )
27+ using ( var server = new SqlStreamStoreServer ( configuration ) )
2428 {
25- return await program . Run ( ) ;
29+ return await server . Run ( ) ;
2630 }
2731 }
2832
29- private Program ( SqlStreamStoreServerConfiguration configuration )
33+ private SqlStreamStoreServer ( SqlStreamStoreServerConfiguration configuration )
3034 {
3135 Log . Logger = new LoggerConfiguration ( )
3236 . MinimumLevel . Is ( configuration . LogLevel )
37+ . MinimumLevel . Override ( "Microsoft.AspNetCore" , LogEventLevel . Warning )
3338 . Enrich . FromLogContext ( )
34- . WriteTo . Console ( )
39+ . WriteTo . Console (
40+ outputTemplate :
41+ "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}" )
3542 . CreateLogger ( ) ;
3643
37- Log . Information ( configuration . ToString ( ) ) ;
44+ s_Log . Information ( configuration . ToString ( ) ) ;
45+
46+ switch ( configuration . Provider )
47+ {
48+ case inmemory :
49+ if ( configuration . ConnectionString != default )
50+ {
51+ ConfigurationNotSupported ( inmemory , nameof ( _configuration . ConnectionString ) ) ;
52+ }
53+
54+ if ( configuration . Schema != default )
55+ {
56+ ConfigurationNotSupported ( inmemory , nameof ( _configuration . Schema ) ) ;
57+ }
58+
59+ if ( configuration . DisableDeletionTracking )
60+ {
61+ ConfigurationNotSupported ( inmemory , nameof ( _configuration . DisableDeletionTracking ) ) ;
62+ }
63+
64+ break ;
65+ case mysql :
66+ if ( configuration . Schema != default )
67+ {
68+ ConfigurationNotSupported ( mysql , nameof ( _configuration . Schema ) ) ;
69+ }
70+
71+ break ;
72+ }
3873
3974 _configuration = configuration ;
4075 _cts = new CancellationTokenSource ( ) ;
@@ -62,7 +97,7 @@ private async Task<int> Run()
6297 }
6398 catch ( Exception ex )
6499 {
65- Log . Fatal ( ex , "Host terminated unexpectedly." ) ;
100+ s_Log . Fatal ( ex , "Host terminated unexpectedly." ) ;
66101 return 1 ;
67102 }
68103 finally
@@ -82,7 +117,7 @@ private async Task RunServer()
82117 new SqlStreamStoreMiddlewareOptions
83118 {
84119 UseCanonicalUrls = _configuration . UseCanonicalUris ,
85- ServerAssembly = typeof ( Program ) . Assembly
120+ ServerAssembly = typeof ( SqlStreamStoreServer ) . Assembly
86121 } ) )
87122 . UseSerilog ( )
88123 . Build ( ) )
@@ -99,6 +134,12 @@ private Task RunInitialization()
99134 private Task RunDatabaseInitialization ( )
100135 => new DatabaseInitializer ( _configuration ) . Initialize ( _cts . Token ) ;
101136
137+ private static void ConfigurationNotSupported ( string provider , string configurationKey ) =>
138+ s_Log . Warning (
139+ "Configuration key '{configurationKey}' is not supported for provider {provider}. It will be ignored." ,
140+ configurationKey ,
141+ provider ) ;
142+
102143 public void Dispose ( )
103144 {
104145 _cts ? . Dispose ( ) ;
0 commit comments