简体   繁体   English

ServiceStack.JsonServiceClient.HttpLog 未填充

[英]ServiceStack.JsonServiceClient.HttpLog is not populating

I'm having trouble enabling logging for a ServiceStack.JsonServiceClient .我无法为ServiceStack.JsonServiceClient启用日志记录。 I'm working from the documentation Capture HTTP Headers in .NET Service Clients but I must be missing something becasue I'm only ever getting an empty string .我正在根据文档Capture HTTP Headers in .NET Service Clients工作,但我必须遗漏一些东西,因为我只得到一个空string

Here's my code:这是我的代码:

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()
}
    

Because I have Api.CaptureHttp(true, true) it is logging the info to the test log but I want to be able to capture the httpLog in code and like I said, it's only ever an empty string there.因为我有Api.CaptureHttp(true, true)它正在将信息记录到测试日志中,但我希望能够在代码中捕获 httpLog,就像我说的那样,它只是一个空string

CaptureHttp has 3 flags: CaptureHttp有 3 个标志:

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

You're only setting Api.CaptureHttp(print:true,log:true) which should print to the console and log to your logger if IsDebugEnabled , your call only sets the first 2 flags but you're code is relying on capturing the log to print it out in which case you wanted to specify that it shouldn't clear the HttpLog after each request with:您只设置Api.CaptureHttp(print:true,log:true)如果IsDebugEnabled应该打印到控制台并记录到您的记录器,您的调用仅设置前 2 个标志,但您的代码依赖于捕获日志打印出来,在这种情况下你想指定它不应该在每次请求后清除 HttpLog:

Api.CaptureHttp(clear:false)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ServiceStack JsonServiceClient 响应头 - ServiceStack JsonServiceClient Response Header ServiceStack JsonServiceClient 请求不一致 - ServiceStack JsonServiceClient Requests not consistent 在ServiceStack JsonServiceClient上设置Accept标头 - Set Accept header on ServiceStack JsonServiceClient 反序列化时,ServiceStack JsonServiceClient静默失败 - ServiceStack JsonServiceClient Silently Failing When Deserializing ServiceStack JsonServiceClient,强制为localhost线路上的流量? - ServiceStack JsonServiceClient, force traffic on the wire for localhost? ServiceStack JsonServiceClient使用路由属性发送会引发未找到异常 - ServiceStack JsonServiceClient Send using route attributes throws exception not found 类型&#39;ServiceStack.JsonServiceClient&#39;中的方法&#39;Get&#39;…没有实现 - Method 'Get' in type 'ServiceStack.JsonServiceClient' … does not have an implementation 提取数据时,ServiceStack MsgPackServiceClient失败,但JsonServiceClient起作用 - ServiceStack MsgPackServiceClient fails when fetching data but JsonServiceClient works 什么是在Servicestack JsonServiceClient Get方法上实现重试的最佳解决方案? - Whats the best solution to implement retry on Servicestack JsonServiceClient Get method? ServiceStack:如何从JsonServiceClient的Get方法获取StatusCode - ServiceStack :How to get StatusCode from JsonServiceClient Get method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM