在 .txt 文件中记录服务调用
logging services calls in .txt file
我正在尝试使用以下代码
private CModel[] getConfig(string CID, string Program)
{
ServiceManagement.ServiceClient obj;
List<ServiceManagement.ManagementApiRepositoryCConfig> executedService;
obj = new ServiceManagement.ServiceClient();
executedService = new List<SaServiceIdentityManagement.ManagementApiRepositoryCConfig>();
executedService = obj.getClubConfigSingle(CID, Program);
return executedService.Select(x => new CModel
{
CID = CID,
ProgramName = x.Name,
ProgramURL = x.Value,
}).ToArray();
}
和
using (StreamWriter w = File.AppendText("log.txt"))
{
Log("call 1", w);
Log("call 2", w);
}
我想要做的是构建一个 .txt 或 xml、js/json 文件来记录对服务的请求
我不确定为什么我没有向 log.txt 文件添加任何内容
谢谢 M
听起来您正在尝试构建默认情况下已存在于 .net 框架中的内容。我认为您正在寻找的是 system.diagnostics 中的跟踪功能。尝试将此添加到您的配置文件中:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information,ActivityTracing"
propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\logs\TracingAndLogging-client.svclog" type="System.Diagnostics.XmlWriterTraceListener"
name="xml" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
实施起来既简单又便宜,甚至还有专门的软件可以为您整齐地显示它。
您可以在此处找到有关跟踪的更多信息:https://msdn.microsoft.com/en-us/library/ms751526%28v=vs.110%29.aspx
我正在尝试使用以下代码
private CModel[] getConfig(string CID, string Program)
{
ServiceManagement.ServiceClient obj;
List<ServiceManagement.ManagementApiRepositoryCConfig> executedService;
obj = new ServiceManagement.ServiceClient();
executedService = new List<SaServiceIdentityManagement.ManagementApiRepositoryCConfig>();
executedService = obj.getClubConfigSingle(CID, Program);
return executedService.Select(x => new CModel
{
CID = CID,
ProgramName = x.Name,
ProgramURL = x.Value,
}).ToArray();
}
和
using (StreamWriter w = File.AppendText("log.txt"))
{
Log("call 1", w);
Log("call 2", w);
}
我想要做的是构建一个 .txt 或 xml、js/json 文件来记录对服务的请求
我不确定为什么我没有向 log.txt 文件添加任何内容
谢谢 M
听起来您正在尝试构建默认情况下已存在于 .net 框架中的内容。我认为您正在寻找的是 system.diagnostics 中的跟踪功能。尝试将此添加到您的配置文件中:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information,ActivityTracing"
propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\logs\TracingAndLogging-client.svclog" type="System.Diagnostics.XmlWriterTraceListener"
name="xml" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
实施起来既简单又便宜,甚至还有专门的软件可以为您整齐地显示它。
您可以在此处找到有关跟踪的更多信息:https://msdn.microsoft.com/en-us/library/ms751526%28v=vs.110%29.aspx