繁体   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