diff --git a/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs b/src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs index 67319423bd..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,15 +38,11 @@ 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"); } 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"); } } 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) 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)