66 using System . Threading . Tasks ;
77 using Microsoft . AspNetCore . Hosting ;
88 using Microsoft . Extensions . Configuration ;
9+ using Serilog ;
910 using SqlStreamStore . Streams ;
1011
1112 internal class Program : IDisposable
@@ -20,6 +21,12 @@ internal class Program : IDisposable
2021
2122 public static async Task < int > Main ( string [ ] args )
2223 {
24+ Log . Logger = new LoggerConfiguration ( )
25+ . MinimumLevel . Debug ( )
26+ . Enrich . FromLogContext ( )
27+ . WriteTo . Console ( )
28+ . CreateLogger ( ) ;
29+
2330 using ( var program = new Program ( args ) )
2431 {
2532 return await program . Run ( ) ;
@@ -33,6 +40,7 @@ private Program(string[] args)
3340 _host = new WebHostBuilder ( )
3441 . UseKestrel ( )
3542 . UseStartup ( new DevServerStartup ( _streamStore ) )
43+ . UseSerilog ( )
3644 . Build ( ) ;
3745 _configuration = new ConfigurationBuilder ( )
3846 . AddEnvironmentVariables ( )
@@ -48,6 +56,7 @@ private async Task<int> Run()
4856
4957 if ( Interactive )
5058 {
59+ Log . Warning ( "Running interactively." ) ;
5160 DisplayMenu ( _streamStore ) ;
5261 }
5362
@@ -57,10 +66,13 @@ private async Task<int> Run()
5766 }
5867 catch ( Exception ex )
5968 {
60- Console . Error . WriteLine ( ex . Message ) ;
69+ Log . Fatal ( ex , "Host terminated unexpectedly." ) ;
70+ return 1 ;
71+ }
72+ finally
73+ {
74+ Log . CloseAndFlush ( ) ;
6175 }
62-
63- return 1 ;
6476 }
6577
6678 private static void DisplayMenu ( IStreamStore streamStore , string url = null )
@@ -102,14 +114,14 @@ private static void Write(IStreamStore streamStore, string url, int messageCount
102114
103115 Task . Run ( ( ) => Task . WhenAll (
104116 from streamId in streams
105- select streamStore . AppendToStream ( streamId ,
117+ select streamStore . AppendToStream (
118+ streamId ,
106119 ExpectedVersion . NoStream ,
107120 GenerateMessages ( messageCount ) ) ) ) ;
108121 }
109122
110123 private static NewStreamMessage [ ] GenerateMessages ( int messageCount )
111- {
112- return Enumerable . Range ( 0 , messageCount )
124+ => Enumerable . Range ( 0 , messageCount )
113125 . Select ( _ => new NewStreamMessage (
114126 Guid . NewGuid ( ) ,
115127 "test" ,
@@ -120,7 +132,6 @@ private static NewStreamMessage[] GenerateMessages(int messageCount)
120132 } ] }}",
121133 "{}" ) )
122134 . ToArray ( ) ;
123- }
124135
125136 public void Dispose ( )
126137 {
0 commit comments