// Used by tests internal MutableSnapshot(IRawConfigSnapshot rawConfigSnapshot, IEnumerable <Options.IOptionMetadata> allOptionsMetadata) { foreach (var optionMetadata in allOptionsMetadata) { optionMetadata.ParseAndSetProperty(rawConfigSnapshot, this, new NoopLogger()); } }
public void ParseAndSetProperty(IRawConfigSnapshot rawConfigSnapshot, MutableSnapshot configSnapshot, IApmLogger loggerArg ) { IApmLogger logger = loggerArg.Scoped(nameof(IOptionMetadata)); var parsedValue = ParseValue(logger, rawConfigSnapshot); MutableSnapshotPropertyInfo.SetValue(configSnapshot, parsedValue); }
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)); } }
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); }