Reputation: 51
"Microsoft.Extensions.Logging.LoggerExtensions.LogError" is throwing exception
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Code:
string SomeConstant = "Constant Value";
try
{
//Some Code
}
catch (Exception ex)
{
logger.LogError(ex, ex.Message + " {ValueOne} {ValueTwo} {ValueThree} ", SomeConstant, string.Empty, string.Empty);
return false;
}
All the required parameters for the LogError Method are passed during the function invocation.
Assembly
Microsoft.Extensions.Logging.Abstractions
Version
2.2.0.0
Thanks in advance!
Upvotes: 3
Views: 1542
Reputation: 14088
Below seems work fine on my side:
string SomeConstant = "Constant Value";
try
{
int x = 1; int y = 0;
int a = x / y;
//Some Code
}
catch (Exception ex)
{
log.LogInformation("!!!!!!!!!!!!!!!!");
log.LogError(ex,@"{0} {1} {2}",SomeConstant, string.Empty, string.Empty);
log.LogInformation("!!!!!!!!!!!!!!!!");
}
Upvotes: 2