mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-30 00:22:40 +01:00
Add a small amount of logging to ServerFactory
This commit is contained in:
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -51,16 +52,17 @@ namespace Tgstation.Server.Host
|
||||
var setupWizardHostBuilder = CreateDefaultBuilder()
|
||||
.UseSetupApplication();
|
||||
|
||||
IPostSetupServices postSetupServices;
|
||||
IPostSetupServices<ServerFactory> postSetupServices;
|
||||
using (var setupHost = setupWizardHostBuilder.Build())
|
||||
{
|
||||
postSetupServices = setupHost.Services.GetRequiredService<IPostSetupServices>();
|
||||
postSetupServices = setupHost.Services.GetRequiredService<IPostSetupServices<ServerFactory>>();
|
||||
await setupHost.RunAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (postSetupServices.GeneralConfiguration.SetupWizardMode == SetupWizardMode.Only)
|
||||
{
|
||||
return null;
|
||||
if (postSetupServices.GeneralConfiguration.SetupWizardMode == SetupWizardMode.Only)
|
||||
{
|
||||
postSetupServices.Logger.LogInformation("Shutting down due to only running setup wizard.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var hostBuilder = CreateDefaultBuilder()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Tgstation.Server.Host.Setup
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="IPostSetupServices"/> with a <see cref="Logger"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TLoggerType">The category <see cref="global::System.Type"/> for <see cref="Logger"/>.</typeparam>
|
||||
interface IPostSetupServices<TLoggerType> : IPostSetupServices
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ILogger"/>.
|
||||
/// </summary>
|
||||
ILogger<TLoggerType> Logger { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using Tgstation.Server.Host.Configuration;
|
||||
using Tgstation.Server.Host.System;
|
||||
@@ -6,7 +7,7 @@ using Tgstation.Server.Host.System;
|
||||
namespace Tgstation.Server.Host.Setup
|
||||
{
|
||||
/// <inheritdoc />
|
||||
sealed class PostSetupServices : IPostSetupServices
|
||||
sealed class PostSetupServices<TLoggerType> : IPostSetupServices<TLoggerType>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public IPlatformIdentifier PlatformIdentifier { get; }
|
||||
@@ -20,6 +21,9 @@ namespace Tgstation.Server.Host.Setup
|
||||
/// <inheritdoc />
|
||||
public FileLoggingConfiguration FileLoggingConfiguration => fileLoggingConfigurationOptions.Value;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ILogger<TLoggerType> Logger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Backing <see cref="IOptions{TOptions}"/> for <see cref="GeneralConfiguration"/>.
|
||||
/// </summary>
|
||||
@@ -36,19 +40,25 @@ namespace Tgstation.Server.Host.Setup
|
||||
readonly IOptions<FileLoggingConfiguration> fileLoggingConfigurationOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PostSetupServices"/> <see langword="class"/>.
|
||||
/// Initializes a new instance of the <see cref="PostSetupServices{TLoggerType}"/> <see langword="class"/>.
|
||||
/// </summary>
|
||||
/// <param name="platformIdentifier">The value of <see cref="PlatformIdentifier"/>.</param>
|
||||
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/> used to create <see cref="Logger"/>.</param>
|
||||
/// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="GeneralConfiguration"/>.</param>
|
||||
/// <param name="databaseConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="DatabaseConfiguration"/>.</param>
|
||||
/// <param name="fileLoggingConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="FileLoggingConfiguration"/>.</param>
|
||||
public PostSetupServices(
|
||||
IPlatformIdentifier platformIdentifier,
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<GeneralConfiguration> generalConfigurationOptions,
|
||||
IOptions<DatabaseConfiguration> databaseConfigurationOptions,
|
||||
IOptions<FileLoggingConfiguration> fileLoggingConfigurationOptions)
|
||||
{
|
||||
PlatformIdentifier = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
|
||||
if (loggerFactory == null)
|
||||
throw new ArgumentNullException(nameof(loggerFactory));
|
||||
|
||||
Logger = loggerFactory.CreateLogger<TLoggerType>();
|
||||
this.generalConfigurationOptions = generalConfigurationOptions ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
|
||||
this.databaseConfigurationOptions = databaseConfigurationOptions ?? throw new ArgumentNullException(nameof(databaseConfigurationOptions));
|
||||
this.fileLoggingConfigurationOptions = fileLoggingConfigurationOptions ?? throw new ArgumentNullException(nameof(fileLoggingConfigurationOptions));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog.Events;
|
||||
@@ -73,7 +73,7 @@ namespace Tgstation.Server.Host.Setup
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to configure.</param>
|
||||
protected virtual void ConfigureHostedService(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IPostSetupServices, PostSetupServices>();
|
||||
services.AddSingleton(typeof(IPostSetupServices<>), typeof(PostSetupServices<>));
|
||||
services.AddSingleton<IHostedService, SetupWizard>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user