예제 #1
0
        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);
        }
예제 #2
0
        public IServiceProvider ConfigureServices(AppCommandLine commandLine)
        {
            ConfigureLogging(commandLine, _services);
            ConfigureGameConfiguration(commandLine, _services);
            ConfigureServices(_services);
            ConfigureCustom(_services);

            return(_services.BuildServiceProvider());
        }
예제 #3
0
        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();
        }
예제 #4
0
        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();
            }
        }