Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public static partial class LoggerMessage
public static System.Func<Microsoft.Extensions.Logging.ILogger, T1, System.IDisposable> DefineScope<T1>(string formatString) { throw null; }
public static System.Func<Microsoft.Extensions.Logging.ILogger, T1, T2, System.IDisposable> DefineScope<T1, T2>(string formatString) { throw null; }
public static System.Func<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, System.IDisposable> DefineScope<T1, T2, T3>(string formatString) { throw null; }
public static System.Func<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, System.IDisposable> DefineScope<T1, T2, T3, T4>(string formatString) { throw null; }
public static System.Func<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, System.IDisposable> DefineScope<T1, T2, T3, T4, T5>(string formatString) { throw null; }
public static System.Func<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, System.IDisposable> DefineScope<T1, T2, T3, T4, T5, T6>(string formatString) { throw null; }
public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, System.Exception> Define<T1>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, System.Exception> Define<T1, T2>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, System.Exception> Define<T1, T2, T3>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,57 @@ public static Func<ILogger, T1, T2, T3, IDisposable> DefineScope<T1, T2, T3>(str
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>
/// <typeparam name="T4">The type of the fourth 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, IDisposable> DefineScope<T1, T2, T3, T4>(string formatString)
{
var formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 4);

return (logger, arg1, arg2, arg3, arg4) => logger.BeginScope(new LogValues<T1, T2, T3, T4>(formatter, arg1, arg2, arg3, arg4));
}

/// <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>
/// <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, IDisposable> DefineScope<T1, T2, T3, T4, T5>(string formatString)
{
var formatter = CreateLogValuesFormatter(formatString, expectedNamedParameterCount: 5);

return (logger, arg1, arg2, arg3, arg4, arg5) => logger.BeginScope(new LogValues<T1, T2, T3, T4, T5>(formatter, arg1, arg2, arg3, arg4, arg5));
}

/// <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 sisxth 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)
{
var 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));
}

/// <summary>
/// Creates a delegate which can be invoked for logging a message.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ public void DefineScope_WithNoParameters_ThrowsException_WhenFormatString_HasNam
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
[InlineData(5)]
[InlineData(6)]
public void DefineScope_ThrowsException_WhenExpectedFormatStringParameterCount_NotFound(
int expectedNamedParameterCount)
{
Expand All @@ -300,6 +303,18 @@ public void DefineScope_ThrowsException_WhenExpectedFormatStringParameterCount_N
exception = Assert.Throws<ArgumentException>(
() => LoggerMessage.DefineScope<string, string, string>(formatString));
break;
case 4:
exception = Assert.Throws<ArgumentException>(
() => LoggerMessage.DefineScope<string, string, string, string>(formatString));
break;
case 5:
exception = Assert.Throws<ArgumentException>(
() => LoggerMessage.DefineScope<string, string, string, string, string>(formatString));
break;
case 6:
exception = Assert.Throws<ArgumentException>(
() => LoggerMessage.DefineScope<string, string, string, string, string, string>(formatString));
break;
default:
throw new ArgumentException($"Invalid value for '{nameof(expectedNamedParameterCount)}'");
}
Expand Down