Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 1c7136d

Browse files
Merge pull request #84 from thefringeninja/fix-services
Improve Logging
2 parents 0e98241 + f3f7cfe commit 1c7136d

11 files changed

+216
-178
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ env:
88
- secure: fKxyki9JzY95G17hNHSy4dgDmH+zXIk50BR6honAz7LmsA9jGv2gg+l1AIUERH3eckdJwxze4K0e5hX88Xfn4j5nN8TnEw7Wwn7c1vjR9FxvRr5cjaJC0SVsOTZj4VC1R9Sqjzrkqv3jJDtDdz9B8aZMdEzJ+BkHwUMFxmuko2p2qabKnAonaGk5VDSTtDyvDMa0aFjKDYuB6MrnrxhfCzLk1ciyGL61SNfz0/u7Hj3xC6v4U0f0BQ9n65l5dIVn+mpuCdQ7GO0HGj0ySo7ffif3qqXXTx7ZWIl3wvf5RCp0PouA8q2dRHYYyGqhhCwuRNU7dfhS/eFtUtcITclZ/DJE86NBQGJ9tpUUhL7BJ3sNJZzbajh1F28paJgi595SKpScp4VGx3iBuDSKH4eb3cRj5TJqCUoscue8/uIZGgR4PGkGF4lbad3b7xexIk1YY/2Rwun1J0N7tqS0rej3ZRZBtipMF64NrVnt9dZzgsIlssZ0W2NvG0vcLX6DUdeZaR0diz8bUl1DXrMFxAUQ/QYxilvaESmCslRElzlb+5eaqQTG5lSP5l6f3ZcKAhvcUGggu9t3vjzpEq3zFa5dorCyK+es1ASNlwZtZr8in9oYkvam9aiDkZD8cEc+9u+qxvnX9w3MsA0P047YCMQGgwRl5dpizoySC3wr52voK7I=
99
- secure: HvSSWjsLR6qFi9/iHMKKoVUT4BDN7h4QjKHLvcrznwpfojrA1+nIlIwgcaIkxi5WClsoPmwW8YInPlyIyV+37+SaNK4sxB2puzwaC3iHBi6Ql38q+olsLdCE8u+DcfEcnzQo8pinNoyBLRjBgHjTAbrwIkLETNOZchss4A4UVhvPSznuNz5imlZxp4LqZ2pW/YcaLeCMQzuJHt5iRM6O4CMu7O4kMP/SPQXIXcqqYWI+o4um1JFO5juXBXtrhcTkOHfvGjqZghwma1F3v7zLHtqrbGBxaTLGNj0EIWPQhQEE5wDpvAqLEZcySl0ZjsPQUJd2Uxi9b8mWM1x6WaZTu9uqIy5t9lkCwUkEAwc/LUXZxwL0oi8HncgJvu7Q5KwVn375sJ0CER0Vn1FO8jphnMbpfkqUmbZmkwoIAUENNNYyGEp6zoNnRvaFQTjEW4bL2huPS0g3BgC2xyh8d5ZsPykIgQXlM8EEA2BZkd+ep2rKjOPT94rs5V5IPuVi9FYzFIsc2kpEkKZO/38j6pEAdCVIZp1m0+KRlLNQ9FeaI+xtil95V5ALIEXpc44o5OuUSoxt5ZirYaGSJtUtxo8E+HqpNL5WrTUeE8+aZos6Tu7jF63U2ehwg5xR6EubvrBjWvSHsQKcwDfdeHK2m15S/mVlahpwyyoCASAJtV7mRJI=
1010
matrix:
11-
- LIBRARY_VERSION=1.2.0-beta.3.25 CONTAINER_RUNTIME_VERSION=2.2.5 CONTAINER_RUNTIME=alpine3.9 RUNTIME=alpine-x64
12-
- LIBRARY_VERSION=1.2.0-beta.3.25 CONTAINER_RUNTIME_VERSION=2.2.5 CONTAINER_RUNTIME=alpine3.8 RUNTIME=alpine-x64
13-
- LIBRARY_VERSION=1.2.0-beta.3.25 CONTAINER_RUNTIME_VERSION=2.2.5 CONTAINER_RUNTIME=bionic RUNTIME=ubuntu.18.04-x64
14-
- LIBRARY_VERSION=1.2.0-beta.3.25 CONTAINER_RUNTIME_VERSION=2.2.5 CONTAINER_RUNTIME=stretch-slim RUNTIME=debian.9-x64
11+
- LIBRARY_VERSION=1.2.0-beta.3.28 CONTAINER_RUNTIME_VERSION=2.2.5 CONTAINER_RUNTIME=alpine3.9 RUNTIME=alpine-x64
12+
- LIBRARY_VERSION=1.2.0-beta.3.28 CONTAINER_RUNTIME_VERSION=2.2.5 CONTAINER_RUNTIME=alpine3.8 RUNTIME=alpine-x64
13+
- LIBRARY_VERSION=1.2.0-beta.3.28 CONTAINER_RUNTIME_VERSION=2.2.5 CONTAINER_RUNTIME=bionic RUNTIME=ubuntu.18.04-x64
14+
- LIBRARY_VERSION=1.2.0-beta.3.28 CONTAINER_RUNTIME_VERSION=2.2.5 CONTAINER_RUNTIME=stretch-slim RUNTIME=debian.9-x64
1515
git:
1616
depth: false

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN yarn && \
2020
yarn react-scripts-ts build && \
2121
echo ${CLIENT_VERSION} > /app/.clientversion
2222

23-
FROM mcr.microsoft.com/dotnet/core/sdk:2.2.204-stretch AS build-dotnet
23+
FROM mcr.microsoft.com/dotnet/core/sdk:2.2.300-stretch AS build-dotnet
2424
ARG CLIENT_PACKAGE=@sqlstreamstore/browser
2525
ARG RUNTIME=alpine-x64
2626
ARG LIBRARY_VERSION=1.2.0

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
CONTAINER_RUNTIME=${CONTAINER_RUNTIME:-alpine3.9}
6-
LIBRARY_VERSION=${LIBRARY_VERSION:-1.2.0-beta.3.25}
6+
LIBRARY_VERSION=${LIBRARY_VERSION:-1.2.0-beta.3.28}
77
CLIENT_VERSION=${CLIENT_VERSION:-0.9.3}
88

99
LOCAL_IMAGE="sql-stream-store-server"

src/SqlStreamStore.Server/Browser/SqlStreamStoreBrowserMiddleware.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace SqlStreamStore.Server.Browser
1111
{
1212
internal static class SqlStreamStoreBrowserMiddleware
1313
{
14+
private static readonly ILogger s_Log = Log.ForContext(typeof(SqlStreamStoreBrowserMiddleware));
1415
public static IApplicationBuilder UseSqlStreamStoreBrowser(
1516
this IApplicationBuilder builder,
1617
Type rootType = default)
@@ -23,7 +24,7 @@ public static IApplicationBuilder UseSqlStreamStoreBrowser(
2324
var staticFiles = rootType.Assembly.GetManifestResourceNames()
2425
.Where(name => name.StartsWith(rootType.Namespace));
2526

26-
Log.Debug(
27+
s_Log.Debug(
2728
"The following embedded resources were found and will be served as static content: {staticFiles}",
2829
string.Join(", ", staticFiles));
2930

src/SqlStreamStore.Server/DatabaseInitializer.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
using Npgsql;
77
using Serilog;
88
using SqlStreamStore.Infrastructure;
9+
using static SqlStreamStore.Server.Constants;
910

1011
namespace SqlStreamStore.Server
1112
{
1213
internal class DatabaseInitializer
1314
{
15+
private static readonly ILogger s_Log = Log.ForContext<DatabaseInitializer>();
16+
1417
private readonly SqlStreamStoreServerConfiguration _configuration;
1518

1619
public DatabaseInitializer(SqlStreamStoreServerConfiguration configuration)
@@ -27,14 +30,14 @@ public Task Initialize(CancellationToken cancellationToken = default)
2730
{
2831
switch (_configuration.Provider)
2932
{
30-
case Constants.mssql:
33+
case mssql:
3134
return InitializeMsSql(cancellationToken);
32-
case Constants.mysql:
35+
case mysql:
3336
return InitializeMySql(cancellationToken);
34-
case Constants.postgres:
37+
case postgres:
3538
return InitializePostgres(cancellationToken);
3639
default:
37-
Log.Warning("Provider {provider} has no database initializer.", _configuration.Provider);
40+
s_Log.Warning("Provider {provider} has no database initializer.", _configuration.Provider);
3841
return Task.CompletedTask;
3942
}
4043
}
@@ -45,7 +48,7 @@ private async Task InitializeMySql(CancellationToken cancellationToken)
4548

4649
var cmdText = $"CREATE DATABASE IF NOT EXISTS `{connectionStringBuilder.Database}`";
4750

48-
Log.Information(
51+
s_Log.Information(
4952
"Creating database '{database}' at server '{server}' with the statement: {cmdText}",
5053
connectionStringBuilder.Database,
5154
connectionStringBuilder.Server,
@@ -78,7 +81,7 @@ IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = N'{connectionStringB
7881
CREATE DATABASE [{connectionStringBuilder.InitialCatalog}]
7982
END;
8083
";
81-
Log.Information(
84+
s_Log.Information(
8285
"Creating database '{database}' at server '{server}' with the statement: {cmdText}",
8386
connectionStringBuilder.InitialCatalog,
8487
connectionStringBuilder.DataSource,
@@ -107,7 +110,7 @@ private async Task InitializePostgres(CancellationToken cancellationToken)
107110

108111
var cmdText = $"CREATE DATABASE {connectionStringBuilder.Database}";
109112

110-
Log.Information(
113+
s_Log.Information(
111114
"Creating database '{database}' at server '{server}' with the statement: {cmdText}",
112115
connectionStringBuilder.Database,
113116
connectionStringBuilder.Host,

src/SqlStreamStore.Server/SqlStreamStore.Server.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
66
<LangVersion>latest</LangVersion>
77
<CrossGenDuringPublish>false</CrossGenDuringPublish>
8-
<LibraryVersion Condition="$(LibraryVersion) == ''">1.2.0-beta.3.25</LibraryVersion>
8+
<LibraryVersion Condition="$(LibraryVersion) == ''">1.2.0-beta.3.28</LibraryVersion>
9+
<StartupObject></StartupObject>
910
</PropertyGroup>
1011
<ItemGroup>
1112
<PackageReference Include="ILLink.Tasks" Version="0.1.5-preview-1841731" />

src/SqlStreamStore.Server/SqlStreamStoreFactory.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace SqlStreamStore.Server
66
{
77
internal class SqlStreamStoreFactory
88
{
9+
private static readonly ILogger s_Log = Log.ForContext<SqlStreamStoreFactory>();
10+
911
private readonly SqlStreamStoreServerConfiguration _configuration;
1012

1113
public SqlStreamStoreFactory(SqlStreamStoreServerConfiguration configuration)
@@ -22,7 +24,7 @@ public IStreamStore Create()
2224
{
2325
var provider = _configuration.Provider;
2426

25-
Log.Information("Creating stream store for provider {provider}.", provider);
27+
s_Log.Information("Creating stream store for provider {provider}.", provider);
2628

2729
switch (provider)
2830
{
@@ -39,12 +41,14 @@ public IStreamStore Create()
3941
}
4042
}
4143

42-
public InMemoryStreamStore CreateInMemoryStreamStore()
43-
=> new InMemoryStreamStore();
44+
public InMemoryStreamStore CreateInMemoryStreamStore() => new InMemoryStreamStore();
4445

4546
public MsSqlStreamStoreV3 CreateMsSqlStreamStore()
4647
{
47-
var settings = new MsSqlStreamStoreV3Settings(_configuration.ConnectionString);
48+
var settings = new MsSqlStreamStoreV3Settings(_configuration.ConnectionString)
49+
{
50+
DisableDeletionTracking = _configuration.DisableDeletionTracking
51+
};
4852

4953
if (_configuration.Schema != null)
5054
{
@@ -55,11 +59,17 @@ public MsSqlStreamStoreV3 CreateMsSqlStreamStore()
5559
}
5660

5761
public MySqlStreamStore CreateMySqlStreamStore()
58-
=> new MySqlStreamStore(new MySqlStreamStoreSettings(_configuration.ConnectionString));
62+
=> new MySqlStreamStore(new MySqlStreamStoreSettings(_configuration.ConnectionString)
63+
{
64+
DisableDeletionTracking = _configuration.DisableDeletionTracking
65+
});
5966

6067
public PostgresStreamStore CreatePostgresStreamStore()
6168
{
62-
var settings = new PostgresStreamStoreSettings(_configuration.ConnectionString);
69+
var settings = new PostgresStreamStoreSettings(_configuration.ConnectionString)
70+
{
71+
DisableDeletionTracking = _configuration.DisableDeletionTracking
72+
};
6373

6474
if (_configuration.Schema != null)
6575
{

src/SqlStreamStore.Server/SqlStreamStoreInitializer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace SqlStreamStore.Server
1212
{
1313
internal class SqlStreamStoreInitializer
1414
{
15+
private static readonly ILogger s_Log = Log.ForContext<SqlStreamStoreInitializer>();
16+
1517
private readonly SqlStreamStoreServerConfiguration _configuration;
1618
private readonly SqlStreamStoreFactory _streamStoreFactory;
1719

@@ -37,7 +39,7 @@ public Task Initialize(CancellationToken cancellationToken = default)
3739
case postgres:
3840
return InitializePostgresStreamStore(cancellationToken);
3941
default:
40-
Log.Warning("Provider {provider} has no initialization.", _configuration.Provider);
42+
s_Log.Warning("Provider {provider} has no initialization.", _configuration.Provider);
4143
return Task.CompletedTask;
4244
}
4345
}
@@ -89,7 +91,7 @@ private async Task InitializePostgresStreamStore(CancellationToken cancellationT
8991

9092
private static void SchemaCreationFailed(Func<string> getSchemaCreationScript, Exception ex)
9193
{
92-
Log.Error(
94+
s_Log.Error(
9395
new StringBuilder()
9496
.Append("Could not create schema: {ex}")
9597
.AppendLine()

src/SqlStreamStore.Server/Program.cs renamed to src/SqlStreamStore.Server/SqlStreamStoreServer.cs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
using System.Threading.Tasks;
55
using Microsoft.AspNetCore.Hosting;
66
using Serilog;
7+
using Serilog.Events;
78
using SqlStreamStore.HAL;
9+
using static SqlStreamStore.Server.Constants;
810

911
namespace 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

Comments
 (0)