예제 #1
0
 // Used by tests
 internal MutableSnapshot(IRawConfigSnapshot rawConfigSnapshot, IEnumerable <Options.IOptionMetadata> allOptionsMetadata)
 {
     foreach (var optionMetadata in allOptionsMetadata)
     {
         optionMetadata.ParseAndSetProperty(rawConfigSnapshot, this, new NoopLogger());
     }
 }
예제 #2
0
                public void ParseAndSetProperty(IRawConfigSnapshot rawConfigSnapshot, MutableSnapshot configSnapshot,
                                                IApmLogger loggerArg
                                                )
                {
                    IApmLogger logger      = loggerArg.Scoped(nameof(IOptionMetadata));
                    var        parsedValue = ParseValue(logger, rawConfigSnapshot);

                    MutableSnapshotPropertyInfo.SetValue(configSnapshot, parsedValue);
                }
예제 #3
0
            internal MutableSnapshot(IRawConfigSnapshot rawConfigSnapshot, ITestOutputHelper xUnitOutputHelper)
            {
                var tempLogger = BuildXunitOutputLogger(ConsoleLogger.DefaultLogLevel);

                Options.LogLevelForTestingConfigParsing.ParseAndSetProperty(rawConfigSnapshot, this, tempLogger);
                var parsingLogger = BuildXunitOutputLogger(LogLevelForTestingConfigParsing);

                foreach (var optionMetadata in Options.All)
                {
                    if (optionMetadata == Options.LogLevelForTestingConfigParsing)
                    {
                        continue;
                    }

                    optionMetadata.ParseAndSetProperty(rawConfigSnapshot, this, parsingLogger);
                }

                IApmLogger BuildXunitOutputLogger(LogLevel logLevel)
                {
                    return(new LineWriterToLoggerAdaptor(new XunitOutputToLineWriterAdaptor(xUnitOutputHelper), logLevel).Scoped(ThisClassName));
                }
            }
예제 #4
0
                private T ParseValue(IApmLogger logger, IRawConfigSnapshot rawConfigSnapshot)
                {
                    var optionValue = rawConfigSnapshot.GetValue(Name);

                    if (optionValue == null)
                    {
                        logger.Trace()
                        ?.Log("Returning default value because the given raw configuration doesn't map the option name to a value."
                              + $" Raw configuration source: {rawConfigSnapshot.DbgDescription}."
                              + $" Option name: {Name}."
                              + $" Default value: {DefaultValue}.");
                        return(DefaultValue);
                    }

                    T parsedValue;

                    try
                    {
                        parsedValue = _parser(optionValue);
                    }
                    catch (Exception ex)
                    {
                        logger.Error()
                        ?.LogException(ex, "Returning default value because parsing of the value returned by the given raw configuration failed."
                                       + $" Raw configuration source: {rawConfigSnapshot.DbgDescription}."
                                       + $" Option name: {Name}."
                                       + $" Value: {optionValue}."
                                       + $" Default value: {DefaultValue}.");
                        return(DefaultValue);
                    }

                    logger.Trace()
                    ?.Log("Returning parsed value returned by the given raw configuration."
                          + $" Raw configuration source: {rawConfigSnapshot.DbgDescription}."
                          + $" Option name: {Name}."
                          + $" Value: {optionValue}.");

                    return(parsedValue);
                }