簡體   English   中英

ServiceStack.JsonServiceClient.HttpLog 未填充

[英]ServiceStack.JsonServiceClient.HttpLog is not populating

我無法為ServiceStack.JsonServiceClient啟用日志記錄。 我正在根據文檔Capture HTTP Headers in .NET Service Clients工作,但我必須遺漏一些東西,因為我只得到一個空string

這是我的代碼:

public class Client
{
    private bool Logging { get; }
    
    public Client(bool logging = false)
    {
        Api = new("https://api.service.com/");
        Logging = logging;
        if (Logging) Api.CaptureHttp(true, true);
    }

    public string GetInfo(string name)
    {
        if (Logging) Api.HttpLog.Clear();
        var response = Api.Get(new Requests.GetInfo(name));
        Debug.WriteLine(Api.HttpLog.ToString());
        return response.Result;
    }
}

[Route("/v1/getinfo/{name}")]
[DataContract]
public class GetInfo : Base, IReturn<Responses.GetInfo>
{
    public GetInfo(string name) => Name = name;

    [DataMember(Name = "name")]
    public string Name { get; init; }
}


[TestMethod]
public void Client_GetInfo()
{
    var client = new Client(true);
    client.GetInfo()
}
    

因為我有Api.CaptureHttp(true, true)它正在將信息記錄到測試日志中,但我希望能夠在代碼中捕獲 httpLog,就像我說的那樣,它只是一個空string

CaptureHttp有 3 個標志:

public void CaptureHttp(bool print = false, bool log = false, bool clear = true)

您只設置Api.CaptureHttp(print:true,log:true)如果IsDebugEnabled應該打印到控制台並記錄到您的記錄器,您的調用僅設置前 2 個標志,但您的代碼依賴於捕獲日志打印出來,在這種情況下你想指定它不應該在每次請求后清除 HttpLog:

Api.CaptureHttp(clear:false)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM