/// <summary> /// Test that the Message property is correctly remoted /// </summary> [Test] public void TestRemotedMessageNdcPushPop() { // Setup the remoting appender ConfigureRootAppender(FixFlags.Partial); RemoteLoggingSinkImpl.Instance.Reset(); log4net.Repository.Hierarchy.Logger root = null; root = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root; string testMessage = string.Format("test message [ {0} ]", (new Random()).Next()); using (NDC.Push("value")) {} // Log a message that will be remoted root.Log(Level.Debug, testMessage, null); // Wait for the remoted object to be delivered System.Threading.Thread.Sleep(1000); LoggingEvent[] events = RemoteLoggingSinkImpl.Instance.Events; Assert.AreEqual(1, events.Length, "Expect to receive 1 remoted event"); Assert.AreEqual(testMessage, events[0].RenderedMessage, "Expect Message match after remoting event"); }
/// <summary> /// Sets the log level for logger to either the level provided by the config or an public default. /// </summary> /// <param name="logger">The logger to set the level of.</param> /// <param name="config">The LogConfig to look for the level setting in.</param> private static void SetupLogLevel(log4netLogger logger, ILogConfig config) { logger.Level = logger.Hierarchy.LevelMap[config.LogLevel]; if (logger.Level == null) { logger.Level = log4net.Core.Level.Info; } if (logger.Level == GetAuditLevel()) { logger.Level = Level.Info; logger.Log(Level.Warn, $"Log level was set to {AuditLogName} which is not a valid log level. To enable audit logging, set the auditLog configuration option to true. Log level will be treated as INFO for this run.", null); } if (IsLogLevelDeprecated(logger.Level)) { logger.Log(Level.Warn, string.Format( "The log level, {0}, set in your configuration file has been deprecated. The agent will still log correctly, but you should change to a supported logging level as described in newrelic.config or the online documentation.", logger.Level.ToString()), null); } }
private static void ShutdownStartupLogAppender(log4netLogger logger) { var startupAppender = logger.GetAppender(STARTUP_APPENDER_NAME) as MemoryAppender; if (startupAppender != null) { LoggingEvent[] events = startupAppender.GetEvents(); logger.RemoveAppender(startupAppender); if (events != null) { foreach (LoggingEvent logEvent in events) { logger.Log(logEvent.Level, logEvent.MessageObject, null); } } } }
/// <summary> /// Test that the UserName property is not remoted when doing a Fix.Partial /// </summary> [Test] public void TestPartialFix() { // Setup the remoting appender ConfigureRootAppender(FixFlags.Partial); RemoteLoggingSinkImpl.Instance.Reset(); log4net.Repository.Hierarchy.Logger root = null; root = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root; // Log a message that will be remoted root.Log(Level.Debug, "test message", null); // Wait for the remoted object to be delivered System.Threading.Thread.Sleep(1000); LoggingEvent[] events = RemoteLoggingSinkImpl.Instance.Events; Assert.AreEqual(1, events.Length, "Expect to receive 1 remoted event"); // Grab the event data LoggingEventData eventData = GetLoggingEventData(events[0]); Assert.IsNull(eventData.UserName, "Expect username to be null because only doing a partial fix"); }