Windows Server AppFabric Logging

Using Windows Server AppFabric makes it easier to build, scale and manage Web and composite applications that run on IIS but when it comes to error logging, tracing and performance analysis, things can get a bit tricky. Therefore let’s discuss how to incorporate some logging features into a Windows Communication Foundation (WCF) Web service to relay diagnostic information about the service.

The AppFabric dashboard provides a wealth of information but if you want to use it to consolidate your standard logging routine(s), some additional coding is required. Thankfully that code is available through WCF and Windows Workflow Foundation (WF) Samples for .NET Framework 4 so that functionality can be had very easily and then can be expanded upon (if need be). 

Using the WCFUserEventProvider class will provide the mechanism for logging user defined entries into the dashboard. You can see here that this class exposes 3 methods, each having their own purpose.

After compiling that class into an assembly, it can then be added to a project and used as a black box. Note that the assembly was coded in C# but I selected a VB template for my WCF service and Web site so depending upon what language you feel comfortable in, you can use.

Tying the GenerateError method to a button click event handler will allow 3 different levels (information, warning and error) to be logged to the dashboard, all containing a payload. The payload here is a string which can be as simple as passing an inner exception message for an error that has occurred or as verbose as an XML package. If the string data type doesn’t suit your needs, the ability to change the underlying methods are only a few lines of code away. The benefit of this is obvious, the enabling of logging and tracing but more so by providing a consistent area (IIS in this case) to reference all of this information.

Speaking of IIS, after installing AppFabric the ability to enable diagnostic tracing is as easy as clicking “Configure” and choosing the level of information to log (i.e. Critical, Error, Warning, Information or Verbose). WF and Message Logging are also available within this same dialog. Once enabled, a file with the extension “.svclog” will be created which has an immense amount of data. In our example, we’re concerned with WcfSampleService.Service1 and by looking at the graph, can exactly tell when an activity started and stopped.

Now let’s say there’s a need for more information on a lower level, say what the CLR is doing. Here you can use either “logman” or “xperf” and have these console applications do your bidding. You will have to have the CLR GUID (which is accessible through MSDN for a specific version [e.g. VS10]) and specify a few parameters but once the command is given, a floodgate of information will be had.

[ To use Logman ]

logman start clrevents -p {e13c0d23-ccbc-4e12-931b-d9cc2eee27e4} 0x1CCBD 0x5 -ets -ct perf

logman stop clrevents -ets

This command creates a binary trace file named “clrevents.etl.”

[ To use Xperf ]

xperf -start clr -on e13c0d23-ccbc-4e12-931b-d9cc2eee27e4:0x1CCBD:5 -f clrevents.etl

xperf -stop clr

The Event Trace Log (ETL) file can be viewed if you installed the Windows SDK (i.e. xperf.exe) or the Service Trace Viewer Tool (i.e. SvcTraceViewer.exe). Using either viewer would display something similar to the following graph:

While viewing the ETL in graphical format is great, transforming that file into a summary of events and what those events are composed of is also beneficial. Therefore, use the following command in conjunction with an ETL file to transform it:

[ To use Tracerpt ]

tracerpt clrevents.etl

This command creates two files: “dumpfile.xml” and “summary.txt.”

The “dumpfile.xml” file lists all the events, and “summary.txt” provides a summary of the events.

Sample Summary:

Sample XML:

As you can see, with a little careful planning, debugging performance problems or verifying specific actions were invoked regarding Windows Server AppFabric should be relatively easy since there are many mechanisms to help you with this process.