MS Extensions Logging "LogError" method is throwing exception "Index (zero based) must be greater than or equal to zero"?

1.3k views Asked by At

"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!

1

There are 1 answers

0
Cindy Pau On

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("!!!!!!!!!!!!!!!!");
    }