public void LogMessageWithNestedObjects_UserModifiedRecursionLimit() { //Arrange // For this one-off test, need to re-do the logging configuration to override what is done in setup var target = new DebugTarget("customAttributeTarget"); var layout = new NewRelicJsonLayout(() => _testAgent); layout.MaxRecursionLimit = 3; target.Layout = layout; var config = new LoggingConfiguration(); config.AddTarget(target); config.AddRuleForAllLevels(target); LogManager.Configuration = config; var logger = LogManager.GetLogger("customAttributeLogger"); var alice = new Person { Name = "Alice", Manager = null }; var bob = new Person { Name = "Bob", Manager = alice }; var charlie = new Person { Name = "Charlie", Manager = bob }; var messageTemplate = "Person = {person}"; var formattedMessage = "Person = Charlie"; //Act logger.Info(messageTemplate, charlie); var loggedMessage = target.LastMessage; var resultsDictionary = TestHelpers.DeserializeOutputJSON(loggedMessage); //Assert Asserts.KeyAndValueMatch(resultsDictionary, NewRelicLoggingProperty.MessageText.GetOutputName(), formattedMessage); Asserts.KeyAndValueMatch(resultsDictionary, NewRelicLoggingProperty.MessageTemplate.GetOutputName(), messageTemplate); Assert.IsTrue(resultsDictionary.ContainsKey(UserPropertiesKey)); Asserts.KeyAndValueMatch(resultsDictionary, UserPropertiesKey, JsonValueKind.Object); var userPropertiesDict = TestHelpers.DeserializeOutputJSON(resultsDictionary[UserPropertiesKey].ToString()); Asserts.KeyAndValueMatch(userPropertiesDict, "person", JsonValueKind.Object); var userPropValDict = TestHelpers.DeserializeOutputJSON(userPropertiesDict["person"].ToString()); Asserts.KeyAndValueMatch(userPropValDict, "Name", "Charlie"); Asserts.KeyAndValueMatch(userPropValDict, "Manager", JsonValueKind.Object); }
public void LogMessage_CustomLayoutAttributes_VerifyAttributes() { //Arrange // For this one-off test, need to re-do the logging configuration to override what is done in setup var target = new DebugTarget("customAttributeTarget"); var layout = new NewRelicJsonLayout(() => _testAgent); layout.Attributes.Add(new JsonAttribute(NewRelicLoggingProperty.LineNumber.GetOutputName(), "${callsite-linenumber}", true)); target.Layout = layout; var config = new LoggingConfiguration(); config.AddTarget(target); config.AddRuleForAllLevels(target); LogManager.Configuration = config; var logger = LogManager.GetLogger("customAttributeLogger"); //Act logger.Info(LogMessage); var loggedMessage = target.LastMessage; var resultsDictionary = TestHelpers.DeserializeOutputJSON(loggedMessage); //Assert Asserts.KeyAndValueMatch(resultsDictionary, NewRelicLoggingProperty.MessageText.GetOutputName(), LogMessage); Asserts.KeyAndValueMatch(resultsDictionary, NewRelicLoggingProperty.LogLevel.GetOutputName(), "INFO"); Asserts.KeyAndValueMatch(resultsDictionary, NewRelicLoggingProperty.ThreadId.GetOutputName(), Thread.CurrentThread.ManagedThreadId.ToString()); Asserts.KeyAndValueMatch(resultsDictionary, NewRelicLoggingProperty.ProcessId.GetOutputName(), Process.GetCurrentProcess().Id.ToString()); Assert.IsTrue(resultsDictionary.ContainsKey(NewRelicLoggingProperty.Timestamp.GetOutputName())); Assert.That(resultsDictionary, Does.ContainKey(NewRelicLoggingProperty.LineNumber.GetOutputName())); foreach (var key in linkingMetadataDict.Keys) { Assert.That(resultsDictionary, Does.Not.ContainKey(key), "The agent was running and instrumented the test process."); } }
public NewRelicLogsTarget() { Layout = new NewRelicJsonLayout(); Endpoint = "https://log-api.newrelic.com/log/v1"; }