Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: When audit logging is enabled, no logs are written to the audit log file. #2029

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Agent/NewRelic/Agent/Core/Logging/AuditLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class AuditLog
// a lazy ILogger instance that injects an "Audit" property
private static Lazy<ILogger> _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()
Expand All @@ -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)
{
chynesNR marked this conversation as resolved.
Show resolved Hide resolved
IsAuditLogEnabled = false; // set a flag so Log() can short-circuit when audit log is not enabled

return loggerConfiguration.Filter.ByIncludingOnly($"{LogLevelExtensions.AuditLevel} is null");
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Logging/LoggerBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading