DocumentDB Trace listener

1.5k views Asked by At

I'm trying register DocumentDB tracing with an existing listener. The code snippet below properly traces a single message to my expected listener but not the actual traces generated by the DocumentDB C# client. Am I missing something?

Snippet from Global.asax:

private static TraceSource DocDBSource;
private static TraceListener ExistingListener = new .....;

public void RegisterDocDBListener() {
    DocDBSource = new TraceSource("DocDBTrace");
    DocDBSource.Switch.Level = SourceLevels.Information;
    DocDBSource.Listeners.Add(ExistingListener);
    DocDBSource.TraceInformation("DocDB tracing initialized");
}
1

There are 1 answers

0
Bruce Chen On

According to your description, I have checked the DefaultTrace from DocumentDB client library for .NET as follows:

enter image description here

For Client-side Logging with the .NET DocumentDB Client Library, you could configure the system.diagnostics configuration as follows to collect and persist documentdb log messages to a text file as follows:

<system.diagnostics>
  <sources>
    <source name="DocDBTrace">
      <listeners>
        <!--ConsoleTraceListener-->
        <add name="configConsoleListener" type="System.Diagnostics.ConsoleTraceListener"/>
        <!--TextWriterTraceListener-->
        <add name="myListener"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="TextWriterOutput.log" />
      </listeners>
    </source>
  </sources>
  <switches>
    <add name="ClientSwitch" value="Warning"/>
  </switches>
</system.diagnostics>

Note: The default Log Level is Information, you could change the ClientSwitch to your expected Log Level (Off, Error, Information, Verbose).

Result

  • Console Application

enter image description here

  • Web Application

enter image description here