Exemple #1
0
        static void Main(string[] args)
        {
            var collector = new FakeMetricsCollector();

            new HostBuilder()
            .ConfigureHostConfiguration(builder => builder.AddCommandLine(args))
            .ConfigureAppConfiguration((context, builder) => builder
                                       .AddJsonFile(path: "appsettings.json", optional: false)
                                       .AddJsonFile(
                                           path: $"appsettings.{context.HostingEnvironment.EnvironmentName}.json",
                                           optional: true))
            .ConfigureServices((context, svcs) => svcs
                               .AddSingleton <IProcessorMetricsCollector>(collector)
                               .AddSingleton <IMemoryMetricsCollector>(collector)
                               .AddSingleton <INetworkMetricsCollector>(collector)
                               .AddSingleton <IMetricsDeliverer, FakeMetricsDeliverer>()
                               .AddSingleton <IHostedService, PerformanceMetricsCollector>()

                               .AddOptions()
                               .Configure <MetricsCollectionOptions>(
                                   context.Configuration.GetSection("MetricsCollection")))
            .ConfigureLogging(builder => builder.AddConsole())
            .Build()
            .Run();
        }
Exemple #2
0
        static void Main()
        {
            var collector = new FakeMetricsCollector();

            new HostBuilder()
            .ConfigureServices(svcs => svcs
                               .AddSingleton <IProcessorMetricsCollector>(collector)
                               .AddSingleton <IMemoryMetricsCollector>(collector)
                               .AddSingleton <INetworkMetricsCollector>(collector)
                               .AddSingleton <IMetricsDeliverer, FakeMetricsDeliverer>()
                               .AddSingleton <IHostedService, PerformanceMetricsCollector>())
            .Build()
            .Run();
        }