|
| 1 | +/* Copyright 2021-present MongoDB Inc. |
| 2 | +* |
| 3 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +* you may not use this file except in compliance with the License. |
| 5 | +* You may obtain a copy of the License at |
| 6 | +* |
| 7 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +* |
| 9 | +* Unless required by applicable law or agreed to in writing, software |
| 10 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +* See the License for the specific language governing permissions and |
| 13 | +* limitations under the License. |
| 14 | +*/ |
| 15 | + |
| 16 | +namespace MongoDB.Driver.Core.TestHelpers.Logging |
| 17 | +{ |
| 18 | + public static class ILoggerExtensions |
| 19 | + { |
| 20 | + public static ILogger<T> Decorate<T>(this ILogger<T> logger, string decoration) => |
| 21 | + logger != null ? new LoggerDecorator<T>(logger, decoration) : null; |
| 22 | + |
| 23 | + public static void Error(this ILogger logger, string format, params object[] arguments) => |
| 24 | + logger?.Log(LogLevel.Error, null, format, arguments); |
| 25 | + |
| 26 | + public static void Error<T>(this ILogger<T> logger, string message, params object[] arguments) => |
| 27 | + logger?.Log(LogLevel.Error, null, message, arguments); |
| 28 | + |
| 29 | + public static void Warning(this ILogger logger, string format, params object[] arguments) => |
| 30 | + logger?.Log(LogLevel.Warning, null, format, arguments); |
| 31 | + |
| 32 | + public static void Warning<T>(this ILogger<T> logger, string message, params object[] arguments) => |
| 33 | + logger?.Log(LogLevel.Warning, null, message, arguments); |
| 34 | + |
| 35 | + public static void Info(this ILogger logger, string format, params object[] arguments) => |
| 36 | + logger?.Log(LogLevel.Information, null, format, arguments); |
| 37 | + |
| 38 | + public static void Info<T>(this ILogger<T> logger, string message, params object[] arguments) => |
| 39 | + logger?.Log(LogLevel.Information, null, message, arguments); |
| 40 | + |
| 41 | + public static void Debug(this ILogger logger, string format, params object[] arguments) => |
| 42 | + logger?.Log(LogLevel.Debug, null, format, arguments); |
| 43 | + |
| 44 | + public static void Debug<T>(this ILogger<T> logger, string message, params object[] arguments) => |
| 45 | + logger?.Log(LogLevel.Debug, null, message, arguments); |
| 46 | + |
| 47 | + public static void Trace(this ILogger logger, string format, params object[] arguments) => |
| 48 | + logger?.Log(LogLevel.Trace, null, format, arguments); |
| 49 | + |
| 50 | + public static void Trace<T>(this ILogger<T> logger, string format, params object[] arguments) => |
| 51 | + logger?.Log(LogLevel.Trace, null, format, arguments); |
| 52 | + } |
| 53 | + |
| 54 | + internal static class ILoggerFactoryExtensions |
| 55 | + { |
| 56 | + public static ILogger<TCategory> CreateLogger<TCategory>(this ILoggerFactory loggerFactory, string decoration) => |
| 57 | + loggerFactory?.CreateLogger<TCategory>().Decorate(decoration); |
| 58 | + } |
| 59 | +} |
0 commit comments