This project is read-only.

Project description

The ActivityTrackingLog is a pluggable component intended to provide user and system activity tracking functions for ASP.Net/MVC applications. Represents a set of HTTP handlers and modules that expose activity logging functions along with activity analytics UI and client API.

Scenarios of Use

Easy to configure and use - add ActivityTrackingLog.dll as a reference to your project, copy default configutaion from sample project, call Log.LogActivity(...) from your page and you are done!
The image below presents supported logging scenarious.

usage.png

Collected Data

The data model represents the data being collected by ActivityTrackingLog.
domain.png
  • ActivityItem - stores application activity records. Is mapped to dbo.ActivityTrackingLog database table
    • Sequence - auto incremental number (populated internally)
    • ActivityLogId - unique identifier (populated internally)
    • ApplicationKey - current application name (taken from log/applicationKey config value)
    • ActivityType - ServerSide, ClientSide, System (populated internally)
    • Category - activity category (provided by log caller)
    • ActivityCode - activity code (provided by log caller)
    • Activity - activity name (provided by log caller)
    • IsPostAction - indicates if activity happened in a post action or after action (provided by log caller)
    • UserKey - currently logged in user name or NULL if user not known (populated internally)
    • ClientHost - caller PC IP address or name (populated internally)
    • PageUrl - logged page partial URL (populated internally)
    • QueryString - query params (populated internally)
    • TimeUtc - UTC date and time at the moment when activity happen (populated internally)
    • UserAgentId - foreign key to browser user agent info (populated internally)
  • UserAgentItem - stores user agent records . Is mapped to dbo.ActivityTrackingUserAgent database table. Note: This table keeps unique values by met User Agent string.

Pages generate next types of activity actions:
  • Server Side - by calling Log component directly from C#/VB code. you can find sample usage in the code behind of Default.aspx
  • Client Side - by calling atLog proxy object registered at page start-up in document DOM. You can find the sample usage in the code <script> section of Default.aspx layout
  • System - collected by SystemEventsLoggingModule configured in web.config

Components

The image below presents main classes of ActivityTrackingLog separated by functional areas.

Class_diagram.png
  • Log (ActivityTrackingLog.Utils.Log) - Incapsulates the core logging functionality. Exposes static logging methods to use from your code. Iteracts with storage component.
  • Storage - Currently supported 2 types of storage:
    • InMemory (ActivityTrackingLog.Storage.Implementations.InMemoryRepository) - stores all logged data in application's memory. All statistics are lost after application is restarted or shut down. The only way to limit data in size is to configure oldestDate or recordsLimit
    • Linq to SQL (ActivityTrackingLog.Storage.Implementations.L2SqlRepository) - an MSSQL based storage. Is more reliable since it keeps statistics even after the application is restarted.
  • Client Side Proxy (ActivityTrackingLog.Web.Handlers.ClientSideLogClient) - This http handler provides a javascript proxy class (variable name atLog) for client side logging. Has to be attached to your page as external script file. The output content type is text/javascript.
  • UI (ActivityTrackingLog.Web.Handlers.AnalyticsUI) - This http handler provides activity analitics in two different groups of UI screens. Both groups support 3 types of data presentation: Flat List (ReportType=List), Grouped List (ReportType=GroupedList), Chart (ReportType=Chart) (Planned feature). The output content type is text/html.
    • Standalone Statistics Pages (ViewType=Page) - This group of reports runs out of the box without any need to created your own UI. All report settings are transmitted by query string parameters. The pages from this group use their own styles however you can refuse using them but you cannot attach your styles.
    • Embedded Html Controls (ViewType=Control) - This group of reports requires a custom page to be created in your application. Statistics control is embedded into your page layout preserving your page styles.
  • API (ActivityTrackingLog.Web.Handlers.AnalyticsApi) - This http handler returns statistics data as JSON serialized objects. Supports next data presentation types: Flat List, Grouped List. The output content type is application/json.
  • SystemEventsLogging (ActivityTrackingLog.Web.SystemEventsLoggingModule) - This http module logs a subset of server side page life cycle events. These events appear as System activity records in database. Useful for debugging/tracing, however it doesn't replace standard debugging/tracing functionalities. For best performance disable this module in production environment.

Configuration

Below presented parts of web.config required to configure activity tracking in your application.
  • Section Group Definition
<configSections>
    <!-- activity tracking log section group -->
    <sectionGroup name="activityTrackingLog">
      <section name="log" requirePermission="false"
               type="ActivityTrackingLog.Configuration.ConfigSections.LogConfigSection, ActivityTrackingLog" />
      <section name="storage" requirePermission="false"
               type="ActivityTrackingLog.Configuration.ConfigSections.StorageConfigSection, ActivityTrackingLog" />
      <section name="clientSideAccess" requirePermission="false"
               type="ActivityTrackingLog.Configuration.ConfigSections.ClientAccessConfigSection, ActivityTrackingLog" />
      <section name="ui" requirePermission="false"
               type="ActivityTrackingLog.Configuration.ConfigSections.UiConfigSection, ActivityTrackingLog" />
      <section name="api" requirePermission="false"
               type="ActivityTrackingLog.Configuration.ConfigSections.ApiConfigSection, ActivityTrackingLog" />
    </sectionGroup>
  </configSections>
  • Settings
  <!-- activity tracking log settings -->
  <activityTrackingLog>
    <log enabled="true" applicationKey="YourApplicationName" logSystemEvents="true" logSessionEvents="true" logRequestEvents="true"
         logAuthEvents="true" logUserAgent="true" />
    <storage enabled="true" type="ActivityTrackingLog.Storage.Implementations.InMemoryRepository, ActivityTrackingLog"
             oldestDate="10/10/2011 00:00:00" recordsLimit="10000" connectionString="connection to your database" />
    <clientSideAccess enabled="true" handlerUrl="/ActivityAnalytics/ClientActivitiesHandler.axd"/>
    <ui enabled="true" localOnly="false" />
    <api enabled="true" localOnly="false" />
  </activityTrackingLog>
  • Handlers configuration
<location path="ActivityAnalytics">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
      <!-- this section is used for developmnet server, IIS < 7.0 or IIS >= 7.0 in classic mode -->
      <httpHandlers>
        <add verb="POST,GET,HEAD" path="ActivityAnalyticsUI.axd" type="ActivityTrackingLog.Web.Handlers.AnalyticsUI, ActivityTrackingLog" />
        <add verb="POST,GET,HEAD" path="ActivityAnalyticsApi.axd" type="ActivityTrackingLog.Web.Handlers.AnalyticsApi, ActivityTrackingLog" />
        <add verb="GET" path="ClientSideLogClient.axd" type="ActivityTrackingLog.Web.Handlers.ClientSideLogClient, ActivityTrackingLog" />
        <add verb="POST" path="ClientActivitiesHandler.axd" type="ActivityTrackingLog.Web.Handlers.ClientActivitiesHandler, ActivityTrackingLog" />
      </httpHandlers>
    </system.web>
    <system.webServer>
      <!-- this section is used for IIS >= 7.0 in integrated mode -->
      <handlers>
        <add name="ActivityAnalyticsUI" verb="POST,GET,HEAD" path="ActivityAnalyticsUI.axd"
             type="ActivityTrackingLog.Web.Handlers.AnalyticsUI, ActivityTrackingLog" preCondition="integratedMode" />
        <add name="ActivityAnalyticsApi" verb="POST,GET,HEAD" path="ActivityAnalyticsApi.axd"
             type="ActivityTrackingLog.Web.Handlers.AnalyticsApi, ActivityTrackingLog" preCondition="integratedMode" />
        <add name="ClientSideLogClient" verb="GET" path="ClientSideLogClient.axd"
             type="ActivityTrackingLog.Web.Handlers.ClientSideLogClient, ActivityTrackingLog" preCondition="integratedMode" />
        <add name="ClientActivitiesHandler" verb="POST" path="ClientActivitiesHandler.axd"
             type="ActivityTrackingLog.Web.Handlers.ClientActivitiesHandler, ActivityTrackingLog" preCondition="integratedMode" />
      </handlers>
    </system.webServer>
  </location>
  • Modules Configuration
<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <add name="SystemEventsLogging" type="ActivityTrackingLog.Web.SystemEventsLoggingModule, ActivityTrackingLog" />
    </modules>
  </system.webServer>

Usage

  • ASP.Net Web Forms Application
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        // log server side activity
        var activityItem = Log.LogActivity("WebPages", "HomePageAccessed");
        if (null != activityItem)
            lblLoggedServerMessage.Text = string.Format("This page triggerred an <span class=\"bold italic\">SERVER</span> side activity <span class=\"bold italic\">[{0}]</span> at {1}", activity.ToString(), activityItem.TimeUtc.ToString("MM/dd/yyyy HH:MM:ss.fff"));
    }
}
  • ASP.Net MVC Application
// 1. This will log all accessed actions with Category = "ProductController" , Activity = "ActionName"
[LogActivity()]
public class ProductController : Controller
{
    ...
    // 2. This will log current action with Category = "ProductController" , Activity = "Index"
    [LogActivity()]
    public ActionResult Index()
    {
        // 3. Static method call
        Log.LogActivity("ProductController", "IndexAccessed");

        return View();
     }
    ...
}

Last edited Oct 27, 2011 at 9:31 PM by vadimburak, version 5

Comments

No comments yet.