控制和取消 Kusto SDK 客户端跟踪Controlling and suppressing Kusto SDK client-side tracing

Kusto 客户端库使用常用的跟踪平台。The Kusto Client Libraries use a common platform for tracing. 该平台使用大量跟踪源 (System.Diagnostics.TraceSource),每个跟踪源在其构造过程中都会连接到一组默认的跟踪侦听器 (System.Diagnostics.Trace.Listeners)。The platform uses a large number of trace sources (System.Diagnostics.TraceSource), and each is connected to the default set of trace listeners (System.Diagnostics.Trace.Listeners) during its construction.

如果应用程序具有与默认 System.Diagnostics.Trace 实例关联的跟踪侦听器(例如,通过其 app.config 文件进行关联),则 Kusto 客户端库会向这些侦听器发出跟踪。If an application has trace listeners associated with the default System.Diagnostics.Trace instance (for example, through its app.config file), then the Kusto Client Libraries will emit traces to those listeners.

可以通过编程方式或配置文件来取消或控制跟踪。The tracing can be suppressed or controlled programmatically or through a config file.

以编程方式取消跟踪Suppress tracing programmatically

若要以编程方式从 Kusto 客户端库取消跟踪,请在加载相关库时调用此代码片段:To suppress tracing from the Kusto client libraries programmatically, invoke this piece of code when loading the relevant library:

Kusto.Cloud.Platform.Utils.TraceSourceManager.SetTraceVerbosityForAll(
    Kusto.Cloud.Platform.Utils.TraceVerbosity.Fatal
    );

使用配置文件取消跟踪Use a config file to suppress tracing

若要通过配置文件从 Kusto 客户端库取消跟踪,请修改文件 Kusto.Cloud.Platform.dll.tweaks(在 Kusto.Data 库中随附)。To suppress tracing from the Kusto client libraries through a config file, modify the file Kusto.Cloud.Platform.dll.tweaks (which is included with the Kusto.Data library).

    <!-- Overrides the default trace verbosity level -->
    <add key="Kusto.Cloud.Platform.Utils.Tracing.OverrideTraceVerbosityLevel" value="0" />

备注

要使调整生效,key 值中不能有负号For the tweak to take effect, there must not be a minus sign in the value of key

另一种方法是:An alternative, is:

Kusto.Cloud.Platform.Utils.Anchor.Tweaks.SetProgrammaticAppSwitch(
    "Kusto.Cloud.Platform.Utils.Tracing.OverrideTraceVerbosityLevel",
    "0"
    );

启用 Kusto 客户端库跟踪Enable the Kusto client libraries tracing

若要在 Kusto 客户端库之外启用跟踪,请在应用程序的 app.config 文件中启用 .NET 跟踪。To enable tracing out of the Kusto client libraries, enable .NET tracing in your application's app.config file. 例如,假定应用程序 MyApp.exe 使用 Kusto.Data 客户端库。For example, assume that the application MyApp.exe uses the Kusto.Data client library. 更改文件 MyApp.exe.config,使之包含以下项,在下次启动应用程序时就会启用 Kusto.Data 跟踪。Changing file MyApp.exe.config to include the following, will enable Kusto.Data tracing the next time that the application starts.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <trace indentsize="4">
      <listeners>
        <add type="Kusto.Cloud.Platform.Utils.RollingCsvTraceListener2, Kusto.Cloud.Platform" name="RollingCsvTraceListener" initializeData="RollingLogs" />
        <remove name="Default" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

代码会配置一个跟踪侦听器,该侦听器将写入到名为“RollingLogs”的子目录中的 CSV 文件。The code will configure a trace listener that writes to CSV files in a subdirectory called RollingLogs. 该子目录位于进程的目录中。The subdirectory is located in the process' directory.

备注

也可以使用任何与 .NET 兼容的跟踪侦听器类Any .NET-compatible trace listener class may be used as well

启用 Azure AD 客户端库 (ADAL) 跟踪Enable the Azure AD client libraries (ADAL) tracing

启用 Kusto 客户端库的跟踪后,由 Azure AD 客户端库进行的跟踪也将启用。Once tracing for the Kusto client libraries is enabled, so is the tracing by the Azure AD client libraries. Kusto 客户端库会自动配置 ADAL 跟踪。The Kusto client libraries automatically configure ADAL tracing.