From 588c1ee3a9e63e1ca05fb67b7eb0d26fb398db5a Mon Sep 17 00:00:00 2001 From: Louie Farol Date: Wed, 15 Jan 2025 15:07:48 -0800 Subject: [PATCH] Disable SF logger by default --- .../UnitTests/Logger/SFLoggerPairTest.cs | 8 ++++---- .../UnitTests/Logger/SFLoggerTest.cs | 10 +++++----- Snowflake.Data/Logger/SFLoggerFactory.cs | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Snowflake.Data.Tests/UnitTests/Logger/SFLoggerPairTest.cs b/Snowflake.Data.Tests/UnitTests/Logger/SFLoggerPairTest.cs index f577a640e..8555b0fcd 100644 --- a/Snowflake.Data.Tests/UnitTests/Logger/SFLoggerPairTest.cs +++ b/Snowflake.Data.Tests/UnitTests/Logger/SFLoggerPairTest.cs @@ -38,13 +38,13 @@ public void BeforeTest() public void AfterTest() { // Return to default setting - SFLoggerFactory.EnableSFLogger(); + SFLoggerFactory.UseDefaultSFLogger(); } [Test] public void TestUsingSFLogger() { - SFLoggerFactory.EnableSFLogger(); + SFLoggerFactory.UseDefaultSFLogger(); _loggerPair = SFLoggerFactory.GetLogger(); Assert.IsInstanceOf(_loggerPair); } @@ -127,11 +127,11 @@ private SFLogger GetLogger(bool isEnabled) { if (isEnabled) { - SFLoggerFactory.EnableSFLogger(); + SFLoggerFactory.UseDefaultSFLogger(); } else { - SFLoggerFactory.DisableSFLogger(); + SFLoggerFactory.UseEmptySFLogger(); } return SFLoggerFactory.GetLogger(); diff --git a/Snowflake.Data.Tests/UnitTests/Logger/SFLoggerTest.cs b/Snowflake.Data.Tests/UnitTests/Logger/SFLoggerTest.cs index 9910484e1..f0a2da54a 100644 --- a/Snowflake.Data.Tests/UnitTests/Logger/SFLoggerTest.cs +++ b/Snowflake.Data.Tests/UnitTests/Logger/SFLoggerTest.cs @@ -32,13 +32,13 @@ public static void AfterAll() public void AfterTest() { // Return to default setting - SFLoggerFactory.EnableSFLogger(); + SFLoggerFactory.UseDefaultSFLogger(); } [Test] public void TestUsingSFLogger() { - SFLoggerFactory.EnableSFLogger(); + SFLoggerFactory.UseDefaultSFLogger(); _logger = SFLoggerFactory.GetSFLogger(); Assert.IsInstanceOf(_logger); } @@ -46,7 +46,7 @@ public void TestUsingSFLogger() [Test] public void TestUsingEmptyLogger() { - SFLoggerFactory.DisableSFLogger(); + SFLoggerFactory.UseEmptySFLogger(); _logger = SFLoggerFactory.GetSFLogger(); Assert.IsInstanceOf(_logger); } @@ -173,11 +173,11 @@ private SFLogger GetLogger(bool isEnabled) { if (isEnabled) { - SFLoggerFactory.EnableSFLogger(); + SFLoggerFactory.UseDefaultSFLogger(); } else { - SFLoggerFactory.DisableSFLogger(); + SFLoggerFactory.UseEmptySFLogger(); } return SFLoggerFactory.GetSFLogger(false); diff --git a/Snowflake.Data/Logger/SFLoggerFactory.cs b/Snowflake.Data/Logger/SFLoggerFactory.cs index 8dfb277d7..fa4300996 100755 --- a/Snowflake.Data/Logger/SFLoggerFactory.cs +++ b/Snowflake.Data/Logger/SFLoggerFactory.cs @@ -11,18 +11,20 @@ public class SFLoggerFactory { private static bool s_isCustomLoggerEnabled = false; - private static bool s_isSFLoggerEnabled = true; + private static bool s_isSFLoggerEnabled = false; + + private static bool s_useDefaultSFLogger = true; private static ILogger s_customLogger = null; - public static void DisableSFLogger() + public static void UseEmptySFLogger() { - s_isSFLoggerEnabled = false; + s_useDefaultSFLogger = false; } - public static void EnableSFLogger() + public static void UseDefaultSFLogger() { - s_isSFLoggerEnabled = true; + s_useDefaultSFLogger = true; } public static void DisableCustomLogger() @@ -53,9 +55,13 @@ internal static SFLogger GetLogger() internal static SFLogger GetSFLogger(bool useFileAppender = true) { // If true, return the default/specified logger - if (s_isSFLoggerEnabled) + if (s_useDefaultSFLogger) { var logger = new SFLoggerImpl(typeof(T)); + if (!s_isSFLoggerEnabled) + { + logger.SetLevel(LoggingEvent.OFF); // Logger is disabled by default and can be enabled by the EasyLogging feature + } if (useFileAppender) { var fileAppender = new SFRollingFileAppender()