作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
ServiceClientTracing
类具有static boolean IsEnabled
属性,允许您打开跟踪。但是,当您将属性设置为 true
时,控制台/调试或其他任何地方都不会显示任何输出。
如何设置跟踪以使输出在控制台/调试窗口(或任何地方)中可见?
最佳答案
似乎在 Microsoft.Rest.ClientRuntime
项目中默认不支持此功能,因此您需要指定自己的类。例如:
class DebugTracer : IServiceClientTracingInterceptor
{
public void Information(string message)
{
Debug.WriteLine(message);
}
public void TraceError(string invocationId, Exception exception)
{
Debug.WriteLine("Exception in {0}: {1}", invocationId, exception);
}
public void ReceiveResponse(string invocationId, HttpResponseMessage response)
{
string requestAsString = (response == null ? string.Empty : response.AsFormattedString());
Debug.WriteLine("invocationId: {0}\r\nresponse: {1}", invocationId, requestAsString);
}
public void SendRequest(string invocationId, HttpRequestMessage request)
{
string requestAsString = (request == null ? string.Empty : request.AsFormattedString());
Debug.WriteLine("invocationId: {0}\r\nrequest: {1}", invocationId, requestAsString);
}
public void Configuration(string source, string name, string value)
{
Debug.WriteLine("Configuration: source={0}, name={1}, value={2}", source, name, value);
}
public void EnterMethod(string invocationId, object instance, string method, IDictionary<string, object> parameters)
{
Debug.WriteLine("invocationId: {0}\r\ninstance: {1}\r\nmethod: {2}\r\nparameters: {3}",
invocationId, instance, method, parameters.AsFormattedString());
}
public void ExitMethod(string invocationId, object returnValue)
{
string returnValueAsString = (returnValue == null ? string.Empty : returnValue.ToString());
Debug.WriteLine("Exit with invocation id {0}, the return value is {1}",
invocationId, returnValueAsString);
}
}
Appropriated from Log4NetTracingInterceptor 。
现在,如果您想打开跟踪,您需要做的就是:
ServiceClientTracing.IsEnabled = true;
ServiceClientTracing.AddTracingInterceptor(new DebugTracer());
关于c# - Microsoft Rest ServiceClientTracing - 如何将跟踪结果输出到控制台或调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46943669/
我是一名优秀的程序员,十分优秀!