PostSharp6.3/Caching/Troubleshooting Caching

Troubleshooting Caching

If you need to troubleshoop the caching aspect, you can enable logging for this feature. The procedure is different whether or not you are using PostSharp Diagnostics in your application.

This topic contains the following sections:

Enabling logging of caching with PostSharp Diagnostics

If you use PostSharp Diagnostics for logging, you can enable detailed logging of the caching aspect by enabling the Caching logging role for the whole application or a specific type or namespace.

The following code shows how to log the details of the caching aspect to the system console for the whole application:

C#
LoggingServices.DefaultBackend = new ConsoleLoggingBackend();
LoggingServices.DefaultBackend.DefaultVerbosity.SetMinimalLevel(LogLevel.Debug, LoggingRoles.Caching);
Enabling logging of caching with System.Diagnostics

If you are not using PostSharp Diagnostics, you can enable logging of the caching aspect by configuring the TraceSource named PostSharp.Cache in you app.config or web.config file:

XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
  <system.diagnostics>
    <sources>
      <source name="PostSharp.Cache" switchName="PostSharp.Cache" >
        <listeners>
          <add name="console" />
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="PostSharp.Cache" value="-1" />
    </switches>
    <sharedListeners>
      <add name="console" type="System.Diagnostics.ConsoleTraceListener" initializeData="false"/>
    </sharedListeners>
    <trace autoflush="true" indentsize="4">
      <listeners>
        <add name="console" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>
See Also