From f304863c1d3694d2520682f057fbd4af4d32d641 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Mon, 6 Nov 2023 11:57:41 -0600 Subject: [PATCH 1/3] fix: When audit logging is enabled, no logs are written to the audit log file. --- src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs b/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs index 67319423bd..e554bfcc52 100644 --- a/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs +++ b/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs @@ -45,8 +45,6 @@ public static LoggerConfiguration IncludeOnlyAuditLog(this LoggerConfiguration l public static LoggerConfiguration ExcludeAuditLog(this LoggerConfiguration loggerConfiguration) { - IsAuditLogEnabled = false; // set a flag so Log() can short-circuit when audit log is not enabled - return loggerConfiguration.Filter.ByIncludingOnly($"{LogLevelExtensions.AuditLevel} is null"); } } From a691479fa52fb40836a6969e54238c5a89aca477 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:26:45 -0600 Subject: [PATCH 2/3] Explicitly enable/disable audit logging during logger bootstrapping --- src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs | 4 +--- src/Agent/NewRelic/Agent/Core/Logging/LoggerBootstrapper.cs | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs b/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs index e554bfcc52..a1eacf8e0a 100644 --- a/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs +++ b/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs @@ -12,7 +12,7 @@ public static class AuditLog // a lazy ILogger instance that injects an "Audit" property private static Lazy _lazyAuditLogger = LazyAuditLogger(); - public static bool IsAuditLogEnabled { get; set; } //setter is public only for unit tests, not expected to be use anywhere else + public static bool IsAuditLogEnabled { get; set; } // for unit tests only public static void ResetLazyLogger() @@ -38,8 +38,6 @@ public static void Log(string message) public static LoggerConfiguration IncludeOnlyAuditLog(this LoggerConfiguration loggerConfiguration) { - IsAuditLogEnabled = true; // set a flag so Log() can short-circuit when audit log is not enabled - return loggerConfiguration.Filter.ByIncludingOnly($"{LogLevelExtensions.AuditLevel} is not null"); } diff --git a/src/Agent/NewRelic/Agent/Core/Logging/LoggerBootstrapper.cs b/src/Agent/NewRelic/Agent/Core/Logging/LoggerBootstrapper.cs index 71c27ae57f..7b1741cbd0 100644 --- a/src/Agent/NewRelic/Agent/Core/Logging/LoggerBootstrapper.cs +++ b/src/Agent/NewRelic/Agent/Core/Logging/LoggerBootstrapper.cs @@ -57,6 +57,8 @@ public static void ConfigureLogger(ILogConfig config) { SetupLogLevel(config); + AuditLog.IsAuditLogEnabled = config.IsAuditLogEnabled; + var loggerConfig = new LoggerConfiguration() .MinimumLevel.ControlledBy(_loggingLevelSwitch) .ConfigureAuditLogSink(config) From 73bb1451c187016a08b364433b113fde27bd19c3 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:54:19 -0600 Subject: [PATCH 3/3] Update unit tests --- .../Core.UnitTest/Logging/AuditLogTests.cs | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/tests/Agent/UnitTests/Core.UnitTest/Logging/AuditLogTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Logging/AuditLogTests.cs index 1a72e83450..cfed0c3e7c 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Logging/AuditLogTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Logging/AuditLogTests.cs @@ -1,4 +1,4 @@ -// Copyright 2020 New Relic, Inc. All rights reserved. +// Copyright 2020 New Relic, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 using NUnit.Framework; @@ -30,26 +30,6 @@ public void TearDown() AuditLog.ResetLazyLogger(); } - [Test] - public void IncludeOnlyAuditLog_EnablesAuditLog() - { - Assert.False(AuditLog.IsAuditLogEnabled); - - var _ = new LoggerConfiguration().IncludeOnlyAuditLog(); - - Assert.True(AuditLog.IsAuditLogEnabled); - } - - [Test] - public void ExcludeAuditLog_DisablesAuditLog() - { - AuditLog.IsAuditLogEnabled = true; - - var _ = new LoggerConfiguration().ExcludeAuditLog(); - - Assert.False(AuditLog.IsAuditLogEnabled); - } - [TestCase(true)] [TestCase(false)] public void Log_OnlyLogsWhenAuditLogEnabled(bool logEnabled)