private static void FilteredLog(ILogging logger, LogLevel level, Exception exception, string format, object[] objects) { if (logger.IsEnabled(level)) { logger.Log(level, exception, format, objects); } }
/// <summary> /// /// </summary> /// <param name="log"></param> /// <param name="level"></param> /// <param name="exception"></param> /// <param name="provider"></param> /// <param name="format"></param> /// <param name="args"></param> public static ILogging Write(this ILogging log, Level level, Exception exception, IFormatProvider provider, string format, params object[] args) { if (format.IsNullOrWhiteSpace() || !log.IsEnabled(level)) { return(log); } var message = format; if (args != null && args.Any()) { string[] strArray = new string[args.Length]; for (var i = 0; i < args.Length; i++) { var arg = args[i]; if (arg is string) { strArray.SetValue(arg, i); } else { var json = arg.ToJsonString(); strArray.SetValue(json.IsNullOrWhiteSpace() ? json : arg.ToString(), i); } } if (provider == null) { message = string.Format(message, strArray); } else { message = string.Format(provider, message, strArray); } } return(log.Write(message, level, exception: exception)); }