private static void ConfigureGameConfiguration(AppCommandLine commandLine, ServiceCollection services) { IConfiguration gameConfiguration = new ConfigurationBuilder() .AddJsonFile(commandLine.GameConfig, optional: false) .AddJsonFile(InsertEnvironment(commandLine.GameConfig, commandLine.Environment), optional: true) .Build(); services.Configure <AllOptions>(gameConfiguration); }
public IServiceProvider ConfigureServices(AppCommandLine commandLine) { ConfigureLogging(commandLine, _services); ConfigureGameConfiguration(commandLine, _services); ConfigureServices(_services); ConfigureCustom(_services); return(_services.BuildServiceProvider()); }
private static void ConfigureLogging(AppCommandLine commandLine, ServiceCollection services) { services.AddLogging(logging => { logging.AddSerilog(dispose: true); }); IConfiguration loggingConfiguration = new ConfigurationBuilder() .AddJsonFile(commandLine.LoggingConfig, optional: false) .AddJsonFile(InsertEnvironment(commandLine.LoggingConfig, commandLine.Environment), optional: true) .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(loggingConfiguration) .Enrich.WithProperty("MachineID", commandLine.MachineID) .CreateLogger(); }
private static void Start(AppCommandLine commandLine) { IServiceProvider serviceProvider = new Startup().ConfigureServices(commandLine); IServiceScope scope = serviceProvider.CreateScope(); ILoggerFactory loggerFactory = scope.ServiceProvider.GetRequiredService <ILoggerFactory>(); ILogger logger = loggerFactory.CreateLogger(typeof(Program)); try { IGameEngine gameEngine = scope.ServiceProvider.GetRequiredService <IGameEngine>(); gameEngine.Start(); } catch (Exception exception) { // this is our global exception handler logger.LogError(exception, "Application failed."); } finally { scope.Dispose(); } }