Advanced IIS Logging
  • 13 Jun 2018
  • 3 Minutes To Read
  • Contributors
  • Print
  • Share
  • Dark

Advanced IIS Logging

  • Print
  • Share
  • Dark

Stackify parses IIS logs to capture the usage, error rates, and load times of your web applications. Statistics are gathered at the app level and at the individual URL or action level. Logs are parsed by the Stackify agent continuously and up to 250 distinct URLs will be measured per minute and uploaded to Stackify for aggregation. Stackify only collects the URL, status code, and time taken from the log files. No user identifiable information is collected unless it is contained in the URL itself.

Configuring IIS Logging Settings

In IIS, check to ensure that your Logging:

  • is configured for one log file per Site
  • is using the W3C format

Provided you have these settings configured as described, you should see metrics data appear on your App Dashboard for your web application. (Don't forget to restart IIS so these settings will take effect if you need to change them.)

URLs and MVC Actions

Stackify provides reporting on the performance of the requested actions of your web app. You may notice different types of formatted URLs and actions based on the type of web app, such as:

  • ConfigService.svc - Basic file or WCF service endpoint
  • Stacks/Chart/GetAlerts.aspx - Basic file
  • /Stacks/Chart/GetAlerts/ - Folder path or REST style URL
  • /Stacks/Chart/GetAlerts/ - REST style url with numeric parameter id removed
  • Stacks.Chart.GetAlerts - MVC area, controller, action

Stackify automatically replaces numeric and guid values found in URLs to group unique urls together to a single url or action. REST style urls with parameter strings in the URLs will cause lots of distinct URLs to be found. Query strings are ignored as well.

How to Customize the URL/Action

Within ASP.NET you can use the HttpResponse object to append custom data to the query string field. This can be used to log to your IIS log data that better identifies the source of the actual URL that was requested.


MSDN: Response.AppendToLog Method

Stackify scans the query string data in the IIS log looking for the shown special formatted parameter. If found it is used in place of the URL in the log file. This is great for identifying and logging MVC routes. It could also be used to log more details about WCF requests, or ASP.NET apps with custom URL rewriting rules where the URL itself doesn’t really map well to the code that processes it.

2014-03-12 19:06:19 ::1 POST /OpsManager/Stacks/Chart/GetAlerts/ &ResolvedRoute={CUSTOM-URL-ROUTE} 80 - ::1 UserAgent - 200 0 0 263

Using StackifyLib for MVC Route Logging

If you are using MVC we highly recommend using our StackifyLib.dll which has some simple helper methods for logging the MVC route to your IIS log. It works by inspecting the System.Web.Routing.RouteTable.Routes object to identify the MVC area, controller and action. It appends to the IIS log query string a parameter like so:

2014-03-12 19:06:19 ::1 POST /OpsManager/Stacks/Chart/GetAlerts/ &ResolvedRoute={Stacks.Chart.GetAlerts} 80 - ::1 UserAgent - 200 0 0 263
void MvcApplication_BeginRequest(object sender, EventArgs e)
    HttpApplication app = (HttpApplication)sender;
    HttpContext context = app.Context;
    StackifyLib.Web.RouteResolver resolver = new RouteResolver(context);

Logging WCF Actions

ASP.NET logs all WCF requests as only the file name of the svc file. If your web service has a lot of methods it is impossible to track the usage of each method. WCF has a lot of extensibility and various methods of logging and tracing.

Note: WCF by default does not support using HttpContext or the Response.AppendToLog() functionality. It is only supported when ASP.NET compatibility mode is enabled. Please do so with caution and test your app to ensure enabling it doesn’t cause any harm.

It is possible to use an IDispatchMessageInspector to log the WCF action in the AfterReceiveRequest method. It must be configured as a message inspector in your web config or via an attribute on your WCF class. Doing this will log it for all methods within your WCF service.

public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        string route = instanceContext.GetServiceInstance().GetType().Name;
        var action = OperationContext.Current.IncomingMessageHeaders.Action;
        var operationName = action.Substring(action.LastIndexOf("/", StringComparison.OrdinalIgnoreCase) + 1);
        StackifyLib.Web.RouteResolver.AppendToIISLog(System.Web.HttpContext.Current, route + "/" + operationName);
	catch (Exception)
    return null;
Was This Article Helpful?