[英]Can't log string using NLOG
我無法使用 NLOG 從 HTTP 請求中記錄字符串。 這是代碼:
HttpResponseMessage res = client.PostAsync(path, content).Result;
if (!res.IsSuccessStatusCode)
{
if (File.Exists(tempFilePath))
File.Delete(tempFilePath);
String responseStr = res.Content.ReadAsStringAsync().Result;
//TODO(nassim) : Remplacé ce try catch par juste un retour d'erreur dans les log
//ErrorReponse error = JsonConvert.DeserializeObject<ErrorReponse>(responseStr);
Logger.Debug("Taille du log : " + responseStr.Length);
if(responseStr.Length > 200)
{
Logger.Debug(" 1");
Logger.Error("Erreur d'envoi de Document a Recital : " + responseStr.Substring(0, 200));
}
else
{
Logger.Debug(" 2");
Logger.Error("Erreur d'envoi de Document a Recital : " + responseStr.Substring(0, 10));
}
if (responseStr.Contains("Invalid credentials.") || responseStr.Contains("Token is expired."))
{
refreshToken(vault, storedValues);
storeDocInReciTAL(env);
}
throw new Exception("Erreur d'envoi du document vers reciTAL.");
這是堆棧跟蹤:
如您所見,與 responseStr 連接的行沒有顯示在任何地方。 一開始以為是字符串太長了,結果只有37個字符。
我究竟做錯了什么?
使用結構化日志記錄可以解決問題。 我不明白為什么它不適用於簡單的串聯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.