How do you debug your Nest queries?

前端 未结 8 2020
失恋的感觉
失恋的感觉 2021-02-05 14:02

I\'m new to Nest, and I very likely am not creating my query like I think I am. My question is more along the lines of teach a man to fish rather than give me a fish. However,

8条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-05 14:29

    Tested in Nest 6.2.0

    You can now just do:

    #if DEBUG
      connectionSettings.EnableDebugMode(details =>
      {
        Logger.Debug($"ES Request: {Encoding.UTF8.GetString(details.RequestBodyInBytes ?? new byte[0])}");
        Logger.Verbose($"ES Response: {Encoding.UTF8.GetString(details.ResponseBodyInBytes ?? new byte[0])}");
      });
    #endif
    

    The call EnableDebugMode will automatically call DisableDirectStreaming, PrettyJson, and then OnRequestCompleted, passing in the function you gave it.

    NOTE: There may be a bug somewhere in their response stuff. The response seems to be lacking some closing brackets for some reason.

提交回复
热议问题