public void VariableTest() { Assert.That(LogConfig.GetAttributePaths(), Has.Exactly(Enum.GetValues(typeof(LogAttribute)).Length - 1).Items); // Don't count LogSource. Would mean GetAttributePaths needs to be updated Assert.That(Enum.GetValues(typeof(LogParserFailureHandling)), Has.Exactly(3).Items); // Would mean that the log parsers would need to be updated var logConfigType = typeof(LogConfig); var logConfigMembers = logConfigType.GetMembers().Where(member => member.DeclaringType == logConfigType && !(member.Name.StartsWith("get_") || member.Name.StartsWith("set_"))).ToArray(); // Get all members that are not the internal property methods and are declared in that type explicitly Assert.That(logConfigMembers, Has.Exactly(19).Items); // Would mean Clone needs to be updated }
/// <summary> /// Set the configurations to apply to the log parser. /// </summary> /// <param name="config">Configurations to apply to the log parser.</param> public void SetConfig(LogConfig config) { if (validConfigs && attributePaths != null) { throw new InvalidOperationException("Can only set config once"); } validConfigs = config.IsValid; timestampPath = ParserUtil.ParsePath(config.TimestampPath); messagePath = ParserUtil.ParsePath(config.LogMessagePath); setConfigFailureHandlingCounter.Increment(config.ParsingFailureHandling.ToString()); defaultTransientConfig = new TransientParserConfigs() { FailureHandling = config.ParsingFailureHandling, LogHasRoot = config.LogHasRoot }; attributePaths = new Dictionary <LogAttribute, ParserPathElement[]>(); #if NETSTANDARD2_0 var logConfigType = typeof(LogConfig); foreach (var attribute in LogConfig.GetAttributePaths()) { if (attribute.Key == LogAttribute.Timestamp || attribute.Key == LogAttribute.Message) { continue; } AddAttributePath(attribute.Key, logConfigType.GetProperty(attribute.Value).GetValue(config) as string); } #else AddAttributePath(LogAttribute.ThreadID, config.ThreadIDPath); AddAttributePath(LogAttribute.SourceFile, config.SourceFilePath); AddAttributePath(LogAttribute.Function, config.FunctionPath); AddAttributePath(LogAttribute.SourceLine, config.LogLinePath); AddAttributePath(LogAttribute.Level, config.LogLevelPath); AddAttributePath(LogAttribute.SequenceNumber, config.LogSequencePath); AddAttributePath(LogAttribute.Module, config.ModulePath); AddAttributePath(LogAttribute.Type, config.LogTypePath); AddAttributePath(LogAttribute.Section, config.SectionPath); AddAttributePath(LogAttribute.TraceID, config.TraceIdPath); AddAttributePath(LogAttribute.Context, config.ContextPath); #endif }