Skip to content

Commit

Permalink
(chocolateyGH-1121) API - Do not reset loggers
Browse files Browse the repository at this point in the history
When providing a custom logger, do not reset other loggers.
  • Loading branch information
ferventcoder committed Jan 3, 2017
1 parent 3a1c58f commit 8d03724
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/chocolatey/GetChocolatey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public GetChocolatey()
/// <returns>This <see cref="GetChocolatey"/> instance</returns>
public GetChocolatey SetCustomLogging(ILog logger)
{
Log.InitializeWith(logger);
Log.InitializeWith(logger, resetLoggers: false);
return this;
}

Expand Down
10 changes: 6 additions & 4 deletions src/chocolatey/infrastructure/logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ public static class Log
/// Sets up logging to be with a certain type
/// </summary>
/// <typeparam name="T">The type of ILog for the application to use</typeparam>
public static void InitializeWith<T>() where T : ILog, new()
/// <param name="resetLoggers">Should other loggers be reset?</param>
public static void InitializeWith<T>(bool resetLoggers = true) where T : ILog, new()
{
_logType = typeof (T);
LogExtensions.ResetLoggers();
if (resetLoggers) LogExtensions.ResetLoggers();
}

/// <summary>
/// Sets up logging to be with a certain instance. The other method is preferred.
/// </summary>
/// <param name="loggerType">Type of the logger.</param>
/// <param name="resetLoggers">Should other loggers be reset?</param>
/// <remarks>This is mostly geared towards testing</remarks>
public static void InitializeWith(ILog loggerType)
public static void InitializeWith(ILog loggerType, bool resetLoggers = true)
{
_logType = loggerType.GetType();
_logger = loggerType;
LogExtensions.ResetLoggers();
if (resetLoggers) LogExtensions.ResetLoggers();
}

/// <summary>
Expand Down

0 comments on commit 8d03724

Please sign in to comment.