diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs
index b91c9493bc..4221a24819 100644
--- a/src/Tgstation.Server.Host/Core/Application.cs
+++ b/src/Tgstation.Server.Host/Core/Application.cs
@@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
@@ -55,6 +56,9 @@ namespace Tgstation.Server.Host.Core
///
readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment;
+ ///
+ /// The used for determining when the is
+ ///
readonly TaskCompletionSource startupTcs;
///
@@ -71,6 +75,8 @@ namespace Tgstation.Server.Host.Core
Version = Assembly.GetExecutingAssembly().GetName().Version;
VersionString = String.Format(CultureInfo.InvariantCulture, "{0} v{1}", VersionPrefix, Version);
+
+ logger.LogInformation(VersionString);
}
///
@@ -83,19 +89,28 @@ namespace Tgstation.Server.Host.Core
throw new ArgumentNullException(nameof(services));
services.Configure(configuration.GetSection(UpdatesConfiguration.Section));
- var databaseConfigurationSection = configuration.GetSection(DatabaseConfiguration.Section);
- services.Configure(databaseConfigurationSection);
+ services.Configure(configuration.GetSection(DatabaseConfiguration.Section));
services.Configure(configuration.GetSection(GeneralConfiguration.Section));
+ services.Configure(configuration.GetSection(FileLoggingConfiguration.Section));
+
+ services.AddOptions();
+
+ DatabaseConfiguration databaseConfiguration;
+ FileLoggingConfiguration fileLoggingConfiguration;
+ using (var provider = services.BuildServiceProvider())
+ {
+ var dbOptions = provider.GetRequiredService>();
+ databaseConfiguration = dbOptions.Value;
+
+ var loggingOptions = provider.GetRequiredService>();
+ fileLoggingConfiguration = loggingOptions.Value;
+ }
- var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
var ioManager = new DefaultIOManager();
- //remember, anything you .Get manually can be null if the config is missing
- var fileLoggingConfigurationSection = configuration.GetSection(FileLoggingConfiguration.Section);
- var fileLoggingConfiguration = fileLoggingConfigurationSection.Get();
- if (fileLoggingConfiguration?.Disable != true)
+ if (!fileLoggingConfiguration.Disable)
{
- var logPath = !String.IsNullOrEmpty(fileLoggingConfiguration?.Directory) ? fileLoggingConfiguration.Directory : ioManager.ConcatPath(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), VersionPrefix, "Logs");
+ var logPath = !String.IsNullOrEmpty(fileLoggingConfiguration.Directory) ? fileLoggingConfiguration.Directory : ioManager.ConcatPath(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), VersionPrefix, "Logs");
logPath = ioManager.ConcatPath(logPath, "tgs-{Date}.log");
@@ -131,8 +146,8 @@ namespace Tgstation.Server.Host.Core
}
};
- var logEventLevel = ConvertLogLevel(GetMinimumLogLevel(fileLoggingConfiguration?.LogLevel));
- var microsoftEventLevel = ConvertLogLevel(GetMinimumLogLevel(fileLoggingConfiguration?.MicrosoftLogLevel));
+ var logEventLevel = ConvertLogLevel(GetMinimumLogLevel(fileLoggingConfiguration.LogLevel));
+ var microsoftEventLevel = ConvertLogLevel(GetMinimumLogLevel(fileLoggingConfiguration.MicrosoftLogLevel));
var formatter = new MessageTemplateTextFormatter("{Timestamp:o} {RequestId,13} [{Level:u3}] {SourceContext:l}: {Message} ({EventId:x8}){NewLine}{Exception}", null);
@@ -150,8 +165,6 @@ namespace Tgstation.Server.Host.Core
});
}
- services.AddOptions();
-
services.AddScoped();
const string scheme = "JwtBearer";
@@ -198,7 +211,6 @@ namespace Tgstation.Server.Host.Core
options.SerializerSettings.Converters = new[] { new VersionConverter() };
});
- var databaseConfiguration = databaseConfigurationSection.Get();
void AddTypedContext() where TContext : DatabaseContext
{
@@ -210,8 +222,8 @@ namespace Tgstation.Server.Host.Core
services.AddScoped(x => x.GetRequiredService());
}
- var dbType = databaseConfiguration?.DatabaseType;
- switch (databaseConfiguration?.DatabaseType)
+ var dbType = databaseConfiguration.DatabaseType;
+ switch (dbType)
{
case DatabaseType.MySql:
case DatabaseType.MariaDB:
@@ -236,7 +248,7 @@ namespace Tgstation.Server.Host.Core
services.AddSingleton();
- if (isWindows)
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
services.AddSingleton();
services.AddSingleton();
@@ -298,7 +310,7 @@ namespace Tgstation.Server.Host.Core
throw new ArgumentNullException(nameof(serverControl));
logger.LogInformation(VersionString);
-
+
//attempt to restart the server if the configuration changes
ChangeToken.OnChange(configuration.GetReloadToken, () => serverControl.Restart());