如何在Xrm Tooling工具包中启用CrmServiceClient的日志记录?

时间:2016-06-20 00:29:08

标签: powershell dynamics-crm dynamics-crm-online

我在使用自定义PowerShell cmdlet中的连接字符串构造函数使用最新版本的Xrm Tooling nuget软件包尝试登录CRM Online组织时遇到问题。

我收到了一个相当无用的“无法登录到Dynamics CRM”错误消息,并且我尝试启用跟踪进行故障排除但无法通过修改.dll.config文件来启用它,如下所示({{ 3}}):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="Microsoft.Xrm.Tooling.Connector.CrmServiceClient"
              switchName="Microsoft.Xrm.Tooling.Connector.CrmServiceClient"
              switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="console" type="System.Diagnostics.DefaultTraceListener" />
          <remove name="Default" />
          <add name ="fileListener" />
        </listeners>
      </source>

      <source name="Microsoft.Xrm.Tooling.CrmConnectControl"
              switchName="Microsoft.Xrm.Tooling.CrmConnectControl"
              switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="console" type="System.Diagnostics.DefaultTraceListener" />
          <remove name="Default" />
          <add name ="fileListener" />
        </listeners>
      </source>
    </sources>
    <switches>
      <!--
            Possible values for switches: Off, Error, Warning, Info, Verbose
                Verbose:    includes Error, Warning, Info, Trace levels
                Info:       includes Error, Warning, Info levels
                Warning:    includes Error, Warning levels
                Error:      includes Error level
        -->
      <add name="Microsoft.Xrm.Tooling.Connector.CrmServiceClient" value="Verbose" />
      <add name="Microsoft.Xrm.Tooling.CrmConnectControl" value="Verbose" />
      <add name="Microsoft.Xrm.Tooling.WebResourceUtility" value="Verbose" />
    </switches>
    <sharedListeners>
      <add name="fileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="XRMToolingLogs.log" />
      <!--<add name="eventLogListener" type="System.Diagnostics.EventLogTraceListener" initializeData="XRMTooling" />-->
    </sharedListeners>
  </system.diagnostics>
</configuration>

1 个答案:

答案 0 :(得分:5)

我能够通过以下方式以编程方式配置监听器来解决这个问题:

Microsoft.Xrm.Tooling.Connector.TraceControlSettings.TraceLevel = System.Diagnostics.SourceLevels.All;
Microsoft.Xrm.Tooling.Connector.TraceControlSettings.AddTraceListener(new TextWriterTraceListener("log.txt"));

这指出了实际的错误,即CrmServiceClient期望一个具有组织唯一名称而不是URL名称的URL。