tirsdag 17. april 2012

Trace/logging configuration in Team Foundation Server 11

Here is list of the different trace configurations I use when trying to track down an exception in the TFS.

1. TFS Configuration logs:
Tracing configuration changes
2. TFS Application Tier Trace:
Tracing spesific component in the TFS server. API, Security etc
3. TFS Application Tier Request trace
Trace URL requests to the application tier.
4. TFS Client side trace logging
Traceg TFS traffic from the client side i.e. Visual Studio, office or custom application.
5. TFS 11 Team Web Access trace
Trace for Team Web Access.
TFS Configuration logs

The Configuration logs are used when tracking issues during TFS configuration, such as migration/upgrading/backup/attach/detach etc etc.

The logs are available from the TFS Admin console and/or directly from

C:\ProgramData\Microsoft\Team Foundation\Server Configuration\Logs

TFS Application Tier Trace Logging
The TFS application Tier Trace logging enables component level trace logging on the App tier. These logs track all usage of the app tier. To configure the App Tier logging do the follwing: 

1) Open the web.config at C:\Program Files\Microsoft Team Foundation Server Dev11\Application Tier\Web Services\

2) Locate the appSettings block and append the following keys:

<add key="traceWriter" value="true" />
<add key="traceDirectoryName" value="%TEMP%\\TFLogFiles" />
Remember that the %TEMP% folder is the folder for the identity of the application pool for the TFS web application. The App pool identity can be found at
IIS Manager-> Application pools ->Microsoft Team Foundation Server Application Pool -> Advanced Settings:


The folder will be: C:\users\[TFS APP POOL IDENTITY]\AppData\Local\Temp\TFLogFiles

3) To control the diagnostic level go to the system.diagnotics section and change the different trace level for the switches:

<assert assertuienabled="true" />
<trace autoflush="false" indentsize="4" />
<!-- Trace Switches
Each of the trace switches should be set to a value between 0 and 4, inclusive.
0: No trace output
1-4: Increasing levels of trace output; see Systems.Diagnostics.TraceLevel
<add name="API" value="4" />
<add name="Authentication" value="0" />
<add name="Authorization" value="0" />
<add name="Database" value="0" />
<add name="General" value="0" />
<!-- WorkItem trace switches -->
<add name="traceLevel" value="4" />

To enable these settings for a certain service go to

Valid web services are: Build, services, VersionControl, Warehouse, and WorkItemTracking

i.e. setting up trace for the VersionControl service

It is not possible to have a trace filter on both service type and component i.e. serivce = Build and component = API.

Remark: when using the web service for setting the trace level, it is not persisted. Thus when the app pool is recycled these settings will be lost. To persist the settings you must use the web.config, but then again you are only able to enable/disable on component not on service level.

TFS Application Tier Request trace
If you want to trace the web request to the application tier you can change the ASP.NET trace. This configuration is also located in the app tier web.config (C:\Program Files\Microsoft Team Foundation Server Dev11\Application Tier\Web Services\)

<trace enabled="true" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />

The trace parameters are described at

To view the trace go to:

TFS Client side trace logging
If you are doing customization to the TFS you might want to enable client side logging. This is done by adding a diagnostic block to the app.config. i.e. Visual Studio trace: devenv.exe.config or word word.exe.config. If the file doesn’t exists just create it and add the following configuration block

<?xml version ="1.0"?>
    <add key="VersionControl.EnableSoapTracing" value="true" />
    <add key="VersionControl.TraceDownloadContent" value="false" />
    <add key="VersionControl.EnableCompression" value="true" />
    <trace autoflush="false" indentsize="4">
        <add name="traceList" type="System.Diagnostics.TextWriterTraceListener"
         initializeData="C:\Temp\TFS.log" />
  <add name="TeamFoundationSoapProxy" value="4" />
        <add name="VersionControl" value="4" />
        <add name="API" value="4" />
        <add name="General" value="4" />
        <add name="Database" value="4" />
        <add name="Authorization" value="4" />
        <add name="Authentication" value="4" />

Team Web Access trace
Tracing the TFS 2010  was possible by enabing the TWA switches (TSWA.General, TSWA.UserControl +++ ) in the diagnostics block, but since the TWA has been completely rewritten it does not seems to work any more.

But don’t despair, using reflector i found a way of enabling trace for the Team Web Access. Trace filters can be enabled by using the registry string “TFS_RAW_TRACING_ENABLED”. 

The trace filter contains the filter settings using the form KEY=VALUE. Each key/value pair pair is separated by a ‘;’. 
They must contain values for the following filter keys: 
Tracepoint, Area, Level and Layer.
By using reflector on the assemblies in the TWA bin folder you can search for any of the Trace* methods in the class TeamFoundationRequestContext or the static TeamFoundationTracingService.TraceExceptionRaw
Here is an sample from the SaveWorkItems method in the TeamFoundationWorkItemService class:

TeamFoundationTracingService.TraceExceptionRaw(0x927bf, TraceLevel.Error, "WebAccess", TfsTraceLayers.Controller, exception2);
This translates to the follwing trace filter:
               Tracepoint= 599999;
               Area = WebAccess;
               Layer = Controller;
               Level = Error;

Here are som other trace filters:

WebAccess exception logging: 
    Tracepoint = 520010 
    Area = WebAccess 
    Layer = Controller
    Level = Error

Exception in the web service handler:
Area = TeamFoundationWebService
Layer= WebSevice
Tracepoint = 0 
Level = Warning

DataLayerAccess Update WIT xml:
     Tracepoint = 900116/900115
     Area: DataAccessLayer
     Layer: DataAccessLayerImpl
     Level: Verbose
To enable the trace filter just add the string value 


to the 

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\

and enter the trace filter i.e. Level=Verbose;Area=WebAccess;Tracepoint=0;Layer=Controller

In addition to the base trace definition, it is possible to have up to 10 additional tracing parameters defined by the registry values ‘TFS_RAW_TRACING_ENABLED_[1-9]’

The logs are available in the EventViewer under 
“Application and Service Logs” -> Microsoft-Team Foundation Server –> Debug
Here is the Exception trace during a work item save