public IEnumerable <LogDatum> ProcessEvent(LoggingEvent loggingEvent, string renderedString) { var patternParser = new PatternParser(loggingEvent); if (renderedString.Contains("%")) { renderedString = patternParser.Parse(renderedString); } LogLog.Debug(_declaringType, string.Format("RenderedString: {0}", renderedString)); if (!_hasParsedProperties) { ParseProperties(patternParser); _hasParsedProperties = true; } _logsEventMessageParser = new LogsEventMessageParser(renderedString, _configOverrides) { DefaultStreamName = _parsedStreamName, DefaultGroupName = _parsedGroupName, DefaultMessage = _parsedMessage, DefaultTimestamp = _dateTimeOffset ?? loggingEvent.TimeStamp }; _logsEventMessageParser.Parse(); return(_logsEventMessageParser.GetParsedData()); }
public void ParenthesizedNames() { var parser = new LogsEventMessageParser("StreamName: (New Name) A tick! GroupName: GName"); parser.Parse(); var data = parser.GetParsedData(); Assert.That(data.Count(), Is.EqualTo(1)); Assert.That(data.Select(x => x.StreamName), Has.All.EqualTo("New Name")); Assert.That(data.Select(x => x.GroupName), Has.All.EqualTo("GName")); Assert.That(data.Select(x => x.Message), Has.All.EqualTo("A tick!")); }
public void NothingRecognizableShouldProduceCount1() { var parser = new LogsEventMessageParser("A tick"); parser.Parse(); var passes = 0; foreach (var r in parser.GetParsedData()) { Assert.AreEqual("unspecified", r.StreamName); Assert.AreEqual("A tick", r.Message); Assert.AreEqual(null, r.Timestamp); Assert.AreEqual("unspecified", r.GroupName); passes++; } Assert.AreEqual(1, passes); }
public void Timestamp_Override() { var parser = new LogsEventMessageParser("A tick! Timestamp: 2012-09-06 17:55:55 +02:00") { DefaultTimestamp = DateTime.Parse("2012-09-06 12:55:55 +02:00") }; parser.Parse(); var data = parser.GetParsedData(); Assert.That(data.Count(), Is.EqualTo(1)); Assert.That(data.Select(x => x.Timestamp), Has.All.EqualTo(DateTime.Parse("2012-09-06 12:55:55"))); Assert.That(data.Select(x => x.Message), Has.All.EqualTo("A tick!")); }
public void SurroundedNames() { var parser = new LogsEventMessageParser("Beginning tick! StreamName: NewName Middle tick! GroupName: GName End tick!"); parser.Parse(); var data = parser.GetParsedData(); Assert.That(data.Count(), Is.EqualTo(1)); Assert.That(data.Select(x => x.StreamName), Has.All.EqualTo("NewName")); Assert.That(data.Select(x => x.GroupName), Has.All.EqualTo("GName")); Assert.That(data.Select(x => x.Message), Has.All.EqualTo("Beginning tick! Middle tick! End tick!")); }