In this post, I will describe how to enable Client-side traces for AppFabric Caching Service. I will also touch upon some basic problems you might face while trying out the same.

To configure the cache client to generate System.Diagnostic.Traces pertaining to the AppFabric cache, please follow the below steps:

Configuration File Option

In your app.config/web.config you need to add <tracing sinkType="DiagnosticSink" traceLevel="Verbose" />, to the appropriate location as per the cases below:

a.       DataCacheClients Section

If you have a ‘dataCacheClients’ section in your app.config/web.config file under <configuration> section, then add the tracing section as below:

<configuration>

  <configSections>

    <section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere" />

  </configSections>

  <dataCacheClients>

    <!--traceLevel can have the following values : Verbose, Info, Warning, Error or Off-->

    <tracing sinkType="DiagnosticSink" traceLevel="Verbose" />

    <dataCacheClient name="default">

      <hosts>

        <host name="[YOUR CACHE ENDPOINT]" cachePort="22233" />

      </hosts>

      <securityProperties mode="Message">

        <messageSecurity authorizationInfo="[YOUR TOKEN]">

        </messageSecurity>

      </securityProperties>

    </dataCacheClient>

  </dataCacheClients>

  ...

</configuration>

 

Note: Tracing section should be a direct child of the <dataCacheClients> section and should not be added under <dataCacheClient> section(s), if <dataCacheClients> section is present.

b.      DataCacheClient Section

If you do not have a <dataCacheClients> section, and the app.config/web.config has only a <dataCacheClient> section, then add the Tracing section as below:

<configuration>

  <configSections>

    <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere" />

  </configSections>

  <dataCacheClient>

<!--traceLevel can have the following values : Verbose, Info, Warning, Error or Off-->

            <tracing sinkType="DiagnosticSink" traceLevel="Verbose" />     

<hosts>

         <host name="[YOUR CACHE ENDPOINT]" cachePort="22233" />

            </hosts>

            <securityProperties mode="Message">

         <messageSecurity authorizationInfo="[YOUR TOKEN]">

         </messageSecurity>

            </securityProperties>

  </dataCacheClient>

    ...

</configuration>

Programmatic Option

You may also choose to set the System.Diagnostic.Trace for cache client programmatically, by calling the below method at any point:

//Argument 1 specifies that a System.Diagnostic.Trace will be used, and

//Argument 2 specifies the trace level filter.

DataCacheClientLogManager.SetSink(DataCacheTraceSink.DiagnosticSink, System.Diagnostics.TraceLevel.Verbose);


You may also change the level at which the trace logs are filtered, programmatically by calling the below method at any stage (say, 5 minutes after your service has started and stabilized you may want to set the cache client trace level to Warning instead of Verbose):

DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Warning);

Troubleshooting

If you are using Azure SDK 1.3 or above, and trying to get cache client side traces within a Web Role using the above mechanism on DevelopmentFabric environment, you will not be able to see the Cache client traces on the Development Fabric Emulator (or DevFabric UI)

-          Reasoning/Explanation for the given behavior

With SDK 1.3, the IIS (Role Runtime) runs in a separate process as compared to web role (for ASP.Net session state provider scenario) and all the logs related to Web Role can be seen in the DevFabric UI, however, the cache client side traces go as part of IIS i.e. the Role Runtime. The DevFabric Emulator attaches its own listener “DevelopmentFabricTraceListener” by default and its UI emits logs only heard by this listener. Since IIS is in a different process, this listener is not present and logs cannot be seen on the DevFabric UI.

-          Resolution

Note: The resolution below is only to see logs for DevFabric scenario; otherwise the logs would go to xStore (Azure Storage Account) in a perfectly fine manner. For your project, add the below in web.config under <system.diagnostics>\<trace>\<listeners> section:

<add type="Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime.DevelopmentFabricTraceListener, Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="DevFabricListener">
   <filter type="" />
</add>

-          You may add this only for your Web.Debug.config, so that when you actually deploy to an Azure environment, this section does not get added as you will use Web.Release.config file.

-          You also need *not* add a reference to the DLL “Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime.dll” as the machine on which you are deploying it on Development Fabric should have this DLL present in GAC (Search for this DLL under %windir%\assembly).

-          Deploy the sample on DevFabric, and you should now be able to see the Cache traces on the Development Fabric UI.

 

For any questions or feedback regarding the Caching service please visit the Windows Azure Storage, CDN and Caching forum.

 

Sharad Agrawal

On behalf of the AppFabric Team