diff --git a/src/NLog.Extensions.Logging/Logging/NLogMessageParameterList.cs b/src/NLog.Extensions.Logging/Logging/NLogMessageParameterList.cs index 8aa2aac2..2b359d91 100644 --- a/src/NLog.Extensions.Logging/Logging/NLogMessageParameterList.cs +++ b/src/NLog.Extensions.Logging/Logging/NLogMessageParameterList.cs @@ -84,19 +84,27 @@ private static bool IsValidParameterList(IReadOnlyList(); + var ex = Assert.Throws(() => runner.Log(Microsoft.Extensions.Logging.LogLevel.Information, 0, null, "{0}{1}", "Test")); + Assert.IsType(ex.InnerException); + } + + [Fact] + public void TestInvalidFormatString2() + { + var runner = GetRunner(new NLogProviderOptions() { CaptureMessageTemplates = false }); + var ex = Assert.Throws(() => runner.Log(Microsoft.Extensions.Logging.LogLevel.Information, 0, null, "{0}{1}", "Test")); + Assert.IsType(ex.InnerException); + } + [Theory] [InlineData(Microsoft.Extensions.Logging.LogLevel.Critical, "NLog.Extensions.Logging.Tests.LoggerTests.Runner|FATAL|message Exception of type 'System.Exception' was thrown.|20")] [InlineData(Microsoft.Extensions.Logging.LogLevel.Debug, "NLog.Extensions.Logging.Tests.LoggerTests.Runner|DEBUG|message Exception of type 'System.Exception' was thrown.|20")] @@ -231,27 +247,27 @@ public void LogDebugWithId() _logger.LogDebug(20, "message with id"); } - public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, int eventId, Exception exception, string message) + public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, int eventId, Exception exception, string message, params object[] args) { switch (logLevel) { case Microsoft.Extensions.Logging.LogLevel.Trace: - _logger.LogTrace(eventId, exception, message); + _logger.LogTrace(eventId, exception, message, args); break; case Microsoft.Extensions.Logging.LogLevel.Debug: - _logger.LogDebug(eventId, exception, message); + _logger.LogDebug(eventId, exception, message, args); break; case Microsoft.Extensions.Logging.LogLevel.Information: - _logger.LogInformation(eventId, exception, message); + _logger.LogInformation(eventId, exception, message, args); break; case Microsoft.Extensions.Logging.LogLevel.Warning: - _logger.LogWarning(eventId, exception, message); + _logger.LogWarning(eventId, exception, message, args); break; case Microsoft.Extensions.Logging.LogLevel.Error: - _logger.LogError(eventId, exception, message); + _logger.LogError(eventId, exception, message, args); break; case Microsoft.Extensions.Logging.LogLevel.Critical: - _logger.LogCritical(eventId, exception, message); + _logger.LogCritical(eventId, exception, message, args); break; default: throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null);