/// <summary> /// Registers the context. Call this method before accessing the property <see cref="LogHelper.Context" />. /// </summary> /// <param name="context">The context.</param> /// <exception cref="System.Exception"></exception> public static void RegisterContext(ILogHelperContext context) { lock (_lockObject) { if (_context != null) { throw new Exception($"The context was already set in {typeof(LogHelper).FullName}."); } _context = context; } }
/// <summary> /// Nulls the value of <see cref="Context" />. Use this in situations when you want to switch to a different logger. /// Normally the logger should be set only once, when the application starts. However in some scenarios the logger /// might need to be reset /// to something else. One such scenario might be changing the logger in tests. /// After the <see cref="Context" /> is set to null using this method, /// <see cref="RegisterContext(ILogHelperContext)" /> can be called again. /// </summary> public static void RemoveContext() { lock (_lockObject) _context = null; }