Skip to content

Commit

Permalink
(GH-516) Fix: Log.InitializeWith doesn't clear cached loggers
Browse files Browse the repository at this point in the history
This mostly affects the specs - if you use the loggers and then later
initialize them with a logger, the already initialized loggers will
still use the NullLogger because they were not cleared.

This could also lead to some very interesting behavior when using the
dll version of Chocolatey.
  • Loading branch information
ferventcoder committed Dec 23, 2015
1 parent d523e7b commit eff02ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/chocolatey/LogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public static class LogExtensions
// return Log(objectName);
//}

/// <summary>
/// Resets the loggers. This allows switching to a new logger and not reusing old loggers that may be already cached.
/// </summary>
public static void ResetLoggers()
{
_dictionary.Value.Clear();
}

/// <summary>
/// Gets the logger for <see cref="T" />.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/chocolatey/infrastructure/logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static class Log
public static void InitializeWith<T>() where T : ILog, new()
{
_logType = typeof (T);
LogExtensions.ResetLoggers();
}

/// <summary>
Expand All @@ -45,6 +46,7 @@ public static void InitializeWith(ILog loggerType)
{
_logType = loggerType.GetType();
_logger = loggerType;
LogExtensions.ResetLoggers();
}

/// <summary>
Expand Down

0 comments on commit eff02ea

Please sign in to comment.