Unwanted quotes when interpolating strings

by Andrey Dengin   Last Updated April 15, 2019 10:26 AM

I have a code that outputs interpolated string to the log Here is an example

_logger.LogDebug($"REQUEST {webRequest.RequestUri}", Id)
WebResponse webResponse = await _httpService.SendRequestAsync(webRequest);
var response = ParseResponse(webResponse);
_logger.LogDebug($"RESPONSE {(int)response.StatusCode} {JsonConvert.SerializeObject(response.Body)}", Id);

In this example, in a first case of calling the function _logger.LogDebug, I get the expected result as a result:

2019-04-15 09:27:24.5027 DEBUG e1701b07-d228-4543-a320-3cb1b7f2e4b0 REQUEST http://url/

But in the second case, the expected result is wrapped in additional quotes.

2019-04-15 09:27:57.2907 DEBUG "e1701b07-d228-4543-a320-3cb1b7f2e4b0 RESPONSE 200 [{...},{...}]"

Here is the _logger.LogDebug method

public void LogDebug(string message, Guid id)
    Logger.Debug($"{id.ToString()} {message}");

The result of the JsonConvert.SerializeObject(response.Body) is a string representation of array of json eg: [{"key":"value","key":"value"},{"key":"value","key":"value"}]

Why do I get additional quotes in the second case and how can I avoid it?

Related Questions

Updated April 23, 2018 19:26 PM

Updated April 25, 2017 08:26 AM

Updated March 31, 2018 17:26 PM

Updated July 09, 2018 11:26 AM

Updated July 15, 2017 12:26 PM