| | 1 | | using Microsoft.Extensions.Logging; |
| | 2 | |
|
| | 3 | | namespace SharpHoundCommonLib |
| | 4 | | { |
| | 5 | | public class CommonLib |
| | 6 | | { |
| | 7 | | private static bool _initialized; |
| | 8 | |
|
| | 9 | | /// <summary> |
| | 10 | | /// Initializes the common library with a log and cache instance. |
| | 11 | | /// If log/cache aren't provided, will use defaults |
| | 12 | | /// </summary> |
| | 13 | | /// <param name="log"></param> |
| | 14 | | /// <param name="cache"></param> |
| | 15 | | public static void InitializeCommonLib(ILogger log = null, Cache cache = null) |
| 0 | 16 | | { |
| 0 | 17 | | if (_initialized) |
| 0 | 18 | | { |
| 0 | 19 | | log?.LogWarning("Common Library is already initialized"); |
| 0 | 20 | | return; |
| | 21 | | } |
| | 22 | |
|
| 0 | 23 | | _initialized = true; |
| 0 | 24 | | if (log != null) |
| 0 | 25 | | Logging.ConfigureLogging(log); |
| | 26 | |
|
| 0 | 27 | | if (cache == null) |
| 0 | 28 | | { |
| 0 | 29 | | var newCache = Cache.CreateNewCache(); |
| 0 | 30 | | Cache.SetCacheInstance(newCache); |
| 0 | 31 | | } |
| | 32 | | else |
| 0 | 33 | | { |
| 0 | 34 | | Cache.SetCacheInstance(cache); |
| 0 | 35 | | } |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Replaces the current logging instance with a new one |
| | 40 | | /// </summary> |
| | 41 | | /// <param name="log"></param> |
| | 42 | | public static void ReconfigureLogging(ILogger log) |
| 0 | 43 | | { |
| 0 | 44 | | Logging.ConfigureLogging(log); |
| 0 | 45 | | } |
| | 46 | | } |
| | 47 | | } |