示例#1
0
 public int OnExecute()
 {
     Console.WriteLine($"               Debug: {x.Debug}");
     Console.WriteLine($"               Trace: {x.Trace}");
     Console.WriteLine($"            LogLevel: {x.GetLogLevel()}");
     Console.WriteLine($"             Verbose: {x.Verbose}");
     Console.WriteLine($"    IsDefaultCommand: {x.IsDefaultCommand}");
     Console.WriteLine($"  RemainingArguments: {string.Join(" ", x.RemainingArguments)}");
     return(_configuration.GetValue <string>("abcd") == "1234" ? 0 : -1);
 }
示例#2
0
        public static IConfigurationBuilder AddApplicationState(
            this IConfigurationBuilder builder,
            [NotNull] IApplicationState state
            )
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            builder.AddInMemoryCollection(
                new Dictionary <string, string>
            {
                [$"{nameof(ApplicationState)}:{nameof(ApplicationState.Debug)}"] =
                    state.Debug.ToString(CultureInfo.InvariantCulture),
                [$"{nameof(ApplicationState)}:{nameof(ApplicationState.Trace)}"] =
                    state.Trace.ToString(CultureInfo.InvariantCulture),
                [$"{nameof(ApplicationState)}:{nameof(ApplicationState.Verbose)}"] =
                    state.Verbose.ToString(CultureInfo.InvariantCulture),
                [$"{nameof(ApplicationState)}:{nameof(ApplicationState.IsDefaultCommand)}"] =
                    state.IsDefaultCommand.ToString(CultureInfo.InvariantCulture)
            }
                );

            var logLevel = state.GetLogLevel();

            if (logLevel.HasValue)
            {
                builder.AddInMemoryCollection(
                    new Dictionary <string, string>
                {
                    [$"{nameof(ApplicationState)}:LogLevel"] = logLevel.ToString()
                }
                    );
            }

            return(builder);
        }