Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public override void ConfigureServices(IServiceCollection services)
        {
            base.ConfigureServices(services);

            var configurationFile = Configuration["ConfigurationPath"];
            var configJson        = File.ReadAllText(configurationFile);

            var configuration = JsonSerializer.Deserialize <DeploymentServiceConfiguration>(configJson, DeploymentUtilities.ConfigurationSerializationOptions);

            var consoleLog = new ConsoleLog(useShortLayout: false, printSeverity: true);
            var arguments  = new LoggerFactoryArguments(new Logger(consoleLog), new EnvironmentVariableHost(), configuration.LoggingSettings)
            {
                TelemetryFieldsProvider = new HostTelemetryFieldsProvider(HostParameters.FromEnvironment())
            };

            var deploymentService = new DeploymentService(
                configuration: configuration,
                deploymentRoot: new AbsolutePath(Configuration["DeploymentRoot"]),
                secretsProviderFactory: keyVaultUri => new KeyVaultSecretsProvider(keyVaultUri),
                clock: SystemClock.Instance,
                uploadConcurrency: Environment.ProcessorCount);

            services.AddSingleton(deploymentService);
            services.AddSingleton <ILogger>(sp =>
            {
                var lifetime          = sp.GetRequiredService <IHostApplicationLifetime>();
                var replacementLogger = LoggerFactory.CreateReplacementLogger(arguments);
                lifetime.ApplicationStopped.Register(() =>
                {
                    replacementLogger.DisposableToken?.Dispose();
                });
                return(replacementLogger.Logger);
            });
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            var deploymentService = new DeploymentService(
                deploymentRoot: new AbsolutePath(Configuration["DeploymentRoot"]),
                secretsProvider: new KeyVaultSecretsProvider(Configuration["KeyVaultUri"]),
                clock: SystemClock.Instance,
                uploadConcurrency: Environment.ProcessorCount);

            var consoleLog = new ConsoleLog(useShortLayout: false, printSeverity: true);
            var logger     = new Logger(consoleLog);

            services.AddSingleton(deploymentService);
            services.AddSingleton <ILogger>(logger);

            // TODO: Dispose loggers? Does service collection already handle this?
        }