[英]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.