public LogValues(LogValuesFormatter formatter, T0 value0, T1 value1, T2 value2) { _formatter = formatter; _value0 = value0; _value1 = value1; _value2 = value2; }
public FormattedLogValues(string format, params object[] values) { if (values != null && values.Length != 0 && format != null) { if (_count >= MaxCachedFormatters) { if (!_formatters.TryGetValue(format, out _formatter)) { _formatter = new LogValuesFormatter(format); } } else { _formatter = _formatters.GetOrAdd(format, f => { Interlocked.Increment(ref _count); return(new LogValuesFormatter(f)); }); } } else { _formatter = null; } _originalMessage = format ?? NullFormat; _values = values; }
/// <summary> /// Creates a delegate which can be invoked to create a log scope. /// </summary> /// <param name="formatString">The named format string</param> /// <returns>A delegate which when invoked creates a log scope.</returns> public static Func<ILogger, IDisposable> DefineScope(string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 0); var logValues = new LogValues(formatter); return logger => logger.BeginScope(logValues); }
public LogValues(LogValuesFormatter formatter, T0 value0, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) { _formatter = formatter; _value0 = value0; _value1 = value1; _value2 = value2; _value3 = value3; _value4 = value4; _value5 = value5; }
/// <summary> /// Creates a delegate which can be invoked for logging a message. /// </summary> /// <typeparam name="T1">The type of the first parameter passed to the named format string.</typeparam> /// <param name="logLevel">The <see cref="LogLevel"/></param> /// <param name="eventId">The event id</param> /// <param name="formatString">The named format string</param> /// <returns>A delegate which when invoked creates a log message.</returns> public static Action <ILogger, T1, Exception> Define <T1>(LogLevel logLevel, EventId eventId, string formatString) { var formatter = new LogValuesFormatter(formatString); return((logger, arg1, exception) => { if (logger.IsEnabled(logLevel)) { logger.Log(logLevel, eventId, new LogValues <T1>(formatter, arg1), exception, LogValues <T1> .Callback); } }); }
/// <summary> /// Creates a delegate which can be invoked for logging a message. /// </summary> /// <param name="logLevel">The <see cref="LogLevel"/></param> /// <param name="eventId">The event id</param> /// <param name="formatString">The named format string</param> /// <returns>A delegate which when invoked creates a log message.</returns> public static Action<ILogger, Exception> Define(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 0); return (logger, exception) => { if (logger.IsEnabled(logLevel)) { logger.Log(logLevel, eventId, new LogValues(formatter), exception, LogValues.Callback); } }; }
/// <summary> /// Creates a delegate which can be invoked for logging a message. /// </summary> /// <typeparam name="T1">The type of the first parameter passed to the named format string.</typeparam> /// <typeparam name="T2">The type of the second parameter passed to the named format string.</typeparam> /// <typeparam name="T3">The type of the third parameter passed to the named format string.</typeparam> /// <typeparam name="T4">The type of the fourth parameter passed to the named format string.</typeparam> /// <typeparam name="T5">The type of the fifth parameter passed to the named format string.</typeparam> /// <typeparam name="T6">The type of the sixth parameter passed to the named format string.</typeparam> /// <param name="logLevel">The <see cref="LogLevel"/></param> /// <param name="eventId">The event id</param> /// <param name="formatString">The named format string</param> /// <returns>A delegate which when invoked creates a log message.</returns> public static Action<ILogger, T1, T2, T3, T4, T5, T6, Exception> Define<T1, T2, T3, T4, T5, T6>(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 6); return (logger, arg1, arg2, arg3, arg4, arg5, arg6, exception) => { if (logger.IsEnabled(logLevel)) { logger.Log(logLevel, eventId, new LogValues<T1, T2, T3, T4, T5, T6>(formatter, arg1, arg2, arg3, arg4, arg5, arg6), exception, LogValues<T1, T2, T3, T4, T5, T6>.Callback); } }; }
private static LogValuesFormatter CreateLogValuesFormatter(string formatString, int expectedNamedParameterCount) { var logValuesFormatter = new LogValuesFormatter(formatString); int actualCount = logValuesFormatter.ValueNames.Count; if (actualCount != expectedNamedParameterCount) { throw new ArgumentException( SR.Format(SR.UnexpectedNumberOfNamedParameters, formatString, expectedNamedParameterCount, actualCount)); } return logValuesFormatter; }
private static LogValuesFormatter CreateLogValuesFormatter(string formatString, int expectedNamedParameterCount) { var logValuesFormatter = new LogValuesFormatter(formatString); var actualCount = logValuesFormatter.ValueNames.Count; if (actualCount != expectedNamedParameterCount) { throw new ArgumentException(""); } return(logValuesFormatter); }
private static LogValuesFormatter CreateLogValuesFormatter(string formatString, int expectedNamedParameterCount) { var logValuesFormatter = new LogValuesFormatter(formatString); var actualCount = logValuesFormatter.ValueNames.Count; if (actualCount != expectedNamedParameterCount) { throw new ArgumentException( $"The format string '{formatString}' does not have the expected number of named parameters.Expected {expectedNamedParameterCount} parameter(s) but found {actualCount} parameter(s)."); } return(logValuesFormatter); }
/// <summary> /// Creates a delegate which can be invoked for logging a message. /// </summary> /// <typeparam name="T1">The type of the first parameter passed to the named format string.</typeparam> /// <typeparam name="T2">The type of the second parameter passed to the named format string.</typeparam> /// <typeparam name="T3">The type of the third parameter passed to the named format string.</typeparam> /// <typeparam name="T4">The type of the fourth parameter passed to the named format string.</typeparam> /// <param name="logLevel">The <see cref="LogLevel"/></param> /// <param name="eventId">The event id</param> /// <param name="formatString">The named format string</param> /// <returns>A delegate which when invoked creates a log message.</returns> public static Action <ILogger, T1, T2, T3, T4, Exception?> Define <T1, T2, T3, T4>(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 4); void Log(ILogger logger, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Exception?exception) { logger.Log(logLevel, eventId, new LogValues <T1, T2, T3, T4>(formatter, arg1, arg2, arg3, arg4), exception, LogValues <T1, T2, T3, T4> .Callback); } return((logger, arg1, arg2, arg3, arg4, exception) => { if (logger.IsEnabled(logLevel)) { Log(logger, arg1, arg2, arg3, arg4, exception); } }); }
/// <summary> /// Creates a delegate which can be invoked for logging a message. /// </summary> /// <typeparam name="T1">The type of the first parameter passed to the named format string.</typeparam> /// <param name="logLevel">The <see cref="LogLevel"/></param> /// <param name="eventId">The event id</param> /// <param name="formatString">The named format string</param> /// <returns>A delegate which when invoked creates a log message.</returns> public static Action<ILogger, T1, Exception> Define<T1>(LogLevel logLevel, EventId eventId, string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 1); void Log(ILogger logger, T1 arg1, Exception exception) { logger.Log(logLevel, eventId, new LogValues<T1>(formatter, arg1), exception, LogValues<T1>.Callback); } return (logger, arg1, exception) => { if (logger.IsEnabled(logLevel)) { Log(logger, arg1, exception); } }; }
/// <summary> /// Creates a delegate which can be invoked for logging a message. /// </summary> /// <typeparam name="T1">The type of the first parameter passed to the named format string.</typeparam> /// <typeparam name="T2">The type of the second parameter passed to the named format string.</typeparam> /// <typeparam name="T3">The type of the third parameter passed to the named format string.</typeparam> /// <param name="logLevel">The <see cref="LogLevel"/></param> /// <param name="eventId">The event id</param> /// <param name="formatString">The named format string</param> /// <param name="options">The <see cref="LogDefineOptions"/></param> /// <returns>A delegate which when invoked creates a log message.</returns> public static Action <ILogger, T1, T2, T3, Exception?> Define <T1, T2, T3>(LogLevel logLevel, EventId eventId, string formatString, LogDefineOptions?options) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 3); void Log(ILogger logger, T1 arg1, T2 arg2, T3 arg3, Exception?exception) { logger.Log(logLevel, eventId, new LogValues <T1, T2, T3>(formatter, arg1, arg2, arg3), exception, LogValues <T1, T2, T3> .Callback); } if (options != null && options.SkipEnabledCheck) { return(Log); } return((logger, arg1, arg2, arg3, exception) => { if (logger.IsEnabled(logLevel)) { Log(logger, arg1, arg2, arg3, exception); } }); }
/// <summary> /// Creates a delegate which can be invoked for logging a message. /// </summary> /// <typeparam name="T1">The type of the first parameter passed to the named format string.</typeparam> /// <typeparam name="T2">The type of the second parameter passed to the named format string.</typeparam> /// <typeparam name="T3">The type of the third parameter passed to the named format string.</typeparam> /// <typeparam name="T4">The type of the fourth parameter passed to the named format string.</typeparam> /// <typeparam name="T5">The type of the fifth parameter passed to the named format string.</typeparam> /// <typeparam name="T6">The type of the sixth parameter passed to the named format string.</typeparam> /// <param name="logLevel">The <see cref="LogLevel"/></param> /// <param name="eventId">The event id</param> /// <param name="formatString">The named format string</param> /// <param name="skipEnabledCheck">Skips the check if the logging category is enabled.</param> /// <returns>A delegate which when invoked creates a log message.</returns> public static Action <ILogger, T1, T2, T3, T4, T5, T6, Exception?> Define <T1, T2, T3, T4, T5, T6>(LogLevel logLevel, EventId eventId, string formatString, bool skipEnabledCheck) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 6); void Log(ILogger logger, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Exception?exception) { logger.Log(logLevel, eventId, new LogValues <T1, T2, T3, T4, T5, T6>(formatter, arg1, arg2, arg3, arg4, arg5, arg6), exception, LogValues <T1, T2, T3, T4, T5, T6> .Callback); } if (skipEnabledCheck) { return(Log); } return((logger, arg1, arg2, arg3, arg4, arg5, arg6, exception) => { if (logger.IsEnabled(logLevel)) { Log(logger, arg1, arg2, arg3, arg4, arg5, arg6, exception); } }); }
/// <summary> /// Creates a delegate which can be invoked for logging a message. /// </summary> /// <param name="logLevel">The <see cref="LogLevel"/></param> /// <param name="eventId">The event id</param> /// <param name="formatString">The named format string</param> /// <param name="skipEnabledCheck">Skips the check if the logging category is enabled.</param> /// <returns>A delegate which when invoked creates a log message.</returns> public static Action <ILogger, Exception?> Define(LogLevel logLevel, EventId eventId, string formatString, bool skipEnabledCheck) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 0); void Log(ILogger logger, Exception?exception) { logger.Log(logLevel, eventId, new LogValues(formatter), exception, LogValues.Callback); } if (skipEnabledCheck) { return(Log); } return((logger, exception) => { if (logger.IsEnabled(logLevel)) { Log(logger, exception); } }); }
/// <summary> /// Creates a delegate which can be invoked to create a log scope. /// </summary> /// <typeparam name="T1">The type of the first parameter passed to the named format string.</typeparam> /// <typeparam name="T2">The type of the second parameter passed to the named format string.</typeparam> /// <typeparam name="T3">The type of the third parameter passed to the named format string.</typeparam> /// <param name="formatString">The named format string</param> /// <returns>A delegate which when invoked creates a log scope.</returns> public static Func<ILogger, T1, T2, T3, IDisposable> DefineScope<T1, T2, T3>(string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 3); return (logger, arg1, arg2, arg3) => logger.BeginScope(new LogValues<T1, T2, T3>(formatter, arg1, arg2, arg3)); }
/// <summary> /// Creates a delegate which can be invoked to create a log scope. /// </summary> /// <typeparam name="T1">The type of the first parameter passed to the named format string.</typeparam> /// <typeparam name="T2">The type of the second parameter passed to the named format string.</typeparam> /// <typeparam name="T3">The type of the third parameter passed to the named format string.</typeparam> /// <param name="formatString">The named format string</param> /// <returns>A delegate which when invoked creates a log scope.</returns> public static Func <ILogger, T1, T2, T3, IDisposable> DefineScope <T1, T2, T3>(string formatString) { var formatter = new LogValuesFormatter(formatString); return((logger, arg1, arg2, arg3) => logger.BeginScope(new LogValues <T1, T2, T3>(formatter, arg1, arg2, arg3))); }
public LogValues(LogValuesFormatter formatter) { _formatter = formatter; }
/// <summary> /// Creates a delegate which can be invoked to create a log scope. /// </summary> /// <typeparam name="T1">The type of the first parameter passed to the named format string.</typeparam> /// <typeparam name="T2">The type of the second parameter passed to the named format string.</typeparam> /// <typeparam name="T3">The type of the third parameter passed to the named format string.</typeparam> /// <typeparam name="T4">The type of the fourth parameter passed to the named format string.</typeparam> /// <typeparam name="T5">The type of the fifth parameter passed to the named format string.</typeparam> /// <typeparam name="T6">The type of the sixth parameter passed to the named format string.</typeparam> /// <param name="formatString">The named format string</param> /// <returns>A delegate which when invoked creates a log scope.</returns> public static Func <ILogger, T1, T2, T3, T4, T5, T6, IDisposable?> DefineScope <T1, T2, T3, T4, T5, T6>(string formatString) { LogValuesFormatter formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 6); return((logger, arg1, arg2, arg3, arg4, arg5, arg6) => logger.BeginScope(new LogValues <T1, T2, T3, T4, T5, T6>(formatter, arg1, arg2, arg3, arg4, arg5, arg6))); }