An error occurred while writing to logger(s). (Input string was not in a correct format.)

Jak
Jak
Member
392 Points
161 Posts

I'm using nlog with .netcore REST Api as:

using Microsoft.Extensions.Logging;
 }
catch (Exception ex)
{
   Logger.LogCritical(-1, ex, string.Format("error occurred: {0}", ex.Message));
}

But getting error as:

An error occurred while writing to logger(s). (Input string was not in a correct format.) (Invalid format string. Expected 4 format parameters, but failed to lookup parameter index 1)

 

And in Program.cs:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args).
            ConfigureAppConfiguration(config =>
            {
                config
                .AddJsonFile("appsettings.json", false, true);
            })
            .UseNLog()
Views: 81
Total Answered: 1
Total Marked As Answer: 0
Posted On: 30-Sep-2020 03:26

Share:   fb twitter linkedin
Answers
Jak
Jak
Member
392 Points
161 Posts
         

I used to log only error message and did not get any error:

Logger.LogCritical(string.Format("error occurred: {0}", ex.Message));

But I'm not sure what is missing in the following:

Logger.LogCritical(-1, ex, string.Format("error occurred: {0}", ex.Message));
Posted On: 17-Oct-2020 05:39
 Log In to Chat