Skip to content

Commit 8d03724

Browse files
committed
(chocolateyGH-1121) API - Do not reset loggers
When providing a custom logger, do not reset other loggers.
1 parent 3a1c58f commit 8d03724

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/chocolatey/GetChocolatey.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public GetChocolatey()
106106
/// <returns>This <see cref="GetChocolatey"/> instance</returns>
107107
public GetChocolatey SetCustomLogging(ILog logger)
108108
{
109-
Log.InitializeWith(logger);
109+
Log.InitializeWith(logger, resetLoggers: false);
110110
return this;
111111
}
112112

src/chocolatey/infrastructure/logging/Log.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ public static class Log
3131
/// Sets up logging to be with a certain type
3232
/// </summary>
3333
/// <typeparam name="T">The type of ILog for the application to use</typeparam>
34-
public static void InitializeWith<T>() where T : ILog, new()
34+
/// <param name="resetLoggers">Should other loggers be reset?</param>
35+
public static void InitializeWith<T>(bool resetLoggers = true) where T : ILog, new()
3536
{
3637
_logType = typeof (T);
37-
LogExtensions.ResetLoggers();
38+
if (resetLoggers) LogExtensions.ResetLoggers();
3839
}
3940

4041
/// <summary>
4142
/// Sets up logging to be with a certain instance. The other method is preferred.
4243
/// </summary>
4344
/// <param name="loggerType">Type of the logger.</param>
45+
/// <param name="resetLoggers">Should other loggers be reset?</param>
4446
/// <remarks>This is mostly geared towards testing</remarks>
45-
public static void InitializeWith(ILog loggerType)
47+
public static void InitializeWith(ILog loggerType, bool resetLoggers = true)
4648
{
4749
_logType = loggerType.GetType();
4850
_logger = loggerType;
49-
LogExtensions.ResetLoggers();
51+
if (resetLoggers) LogExtensions.ResetLoggers();
5052
}
5153

5254
/// <summary>

0 commit comments

Comments
 (0)