C# 日志服务在.txt文件中调用

C# 日志服务在.txt文件中调用,c#,.net,wcf,C#,.net,Wcf,我正在尝试使用以下代码 private CModel[] getConfig(string CID, string Program) { ServiceManagement.ServiceClient obj; List<ServiceManagement.ManagementApiRepositoryCConfig> executedService; obj = new ServiceManag

我正在尝试使用以下代码

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();
        }  
我想做的是构建一个.txt或xml、js/json文件来记录对服务的请求

我不知道为什么我没有得到任何添加到log.txt文件


谢谢你,听起来你好像在尝试构建在.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>
它的实现既简单又便宜,甚至有一个特殊的软件可以为您整洁地显示它


您可以在此处找到有关跟踪的更多信息:

您实现自己的记录器而不只是使用现有记录器(例如log4net)是否有特殊原因?您尝试了什么?什么有效或无效?您的日志文件是否已创建?它是空的吗?在对File.AppendText的调用中,您没有指定目录,因此您将获得进程的当前目录,该目录可能位于磁盘上的任何位置。它只是一个空的0kb文件
<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>