Logging ASP.NET Session Activity

Both the Scaleout.AspNet and the Scaleout.AspNetAsync providers can perform event tracing if detailed logging information is needed in traditional ASP.NET applications. The providers implement a standard .NET trace source that is named ScaleoutSessionState, allowing you to log diagnostic information to the trace listener of your choice. For example, to configure a listener that logs all session state warnings and errors to a file called “ScaleoutSessionState.log”, you would add the following section to your web.config file:

    <source name="ScaleoutSessionState"
        <add name="textFileListener"
             initializeData="C:\MyTraces\ScaleoutSessionState.log" />
        <remove name="Default" />
    <add name="sessionProviderSwitch" value="Warning" />
  <trace autoflush="true" indentsize="4"/>

The session provider’s trace source offers support for the following trace switch levels:

  • Error: Records information about errors that occur in the session provider, such as connectivity problems with the ScaleOut service. A full stack trace of each exception is sent to the trace listener.

  • Warning: Records unusual (but recoverable) issues that the session provider encounters in the course of processing a web request. Errors are also recorded at this switch level.

  • Verbose: Traces every access made to the session provider. Warnings and errors are also traced. This switch level should only be used during development due to the large amount of trace information that is produced.

The .NET Framework provides several trace listeners, including an EventLogTraceListener that can write to the Windows Event Log. Additionally, there are several open-source projects (such as Essential Diagnostics) that offer a variety of listeners, and most cloud platforms provide TraceListener implementations that integrate with their monitoring facilities.