Example #1
0
        public IHost BuildHost()
#endif
        {
            // SAMPLE: what-the-cli-is-doing

            // The --log-level flag value overrides your application's
            // LogLevel
            if (LogLevelFlag.HasValue)
            {
                Console.WriteLine($"Overwriting the minimum log level to {LogLevelFlag.Value}");
                HostBuilder.ConfigureLogging(x => x.SetMinimumLevel(LogLevelFlag.Value));
            }

            if (VerboseFlag)
            {
                Console.WriteLine("Verbose flag is on.");

                // The --verbose flag adds console and
                // debug logging, as well as setting
                // the minimum logging level down to debug
                HostBuilder.ConfigureLogging(x =>
                {
                    x.SetMinimumLevel(LogLevel.Debug);
                });
            }

            // The --environment flag is used to set the environment
            // property on the IHostedEnvironment within your system
            if (EnvironmentFlag.IsNotEmpty())
            {
                Console.WriteLine($"Overwriting the environment to `{EnvironmentFlag}`");
                HostBuilder.UseEnvironment(EnvironmentFlag);
            }

            if (ConfigFlag.Any())
            {
                HostBuilder.ConfigureAppConfiguration(c => c.AddInMemoryCollection(ConfigFlag));
            }
            // ENDSAMPLE

            return(HostBuilder.Build());
        }
Example #2
0
        public JasperRuntime BuildRuntime()
        {
            // SAMPLE: what-the-cli-is-doing

            // The --log-level flag value overrides your application's
            // LogLevel
            if (LogLevelFlag.HasValue)
            {
                Registry.ConfigureLogging(x => x.SetMinimumLevel(LogLevelFlag.Value));
            }

            if (VerboseFlag)
            {
                Console.WriteLine("Verbose flag is on.");

                // The --verbose flag adds console and
                // debug logging, as well as setting
                // the minimum logging level down to debug
                Registry.ConfigureLogging(x =>
                {
                    x.SetMinimumLevel(LogLevel.Debug);

                    x.AddConsole();
                    x.AddDebug();
                });
            }

            // The --environment flag is used to set the environment
            // property on the IHostedEnvironment within your system
            if (EnvironmentFlag.IsNotEmpty())
            {
                Registry.UseEnvironment(EnvironmentFlag);
            }
            // ENDSAMPLE

            return(JasperRuntime.For(Registry));
        }