How to enable build agent or build controller’s logs?

Here are the steps which I typically perform to enable build agent/controller logs.

1. Go to the build agent/controller installation directory (typically it is something like C:\Program Files\Microsoft Team Foundation Server 2010\Tools).

2. Create a new configuration file named TFSBuildServiceHost.exe.config with the following content:

<configuration>
    <system.diagnostics>
        <switches>
            <add name="BuildServiceTraceLevel" value="4"/>
        </switches>
        <trace autoflush="true" indentsize="4">
            <listeners>
                <add name="myListener" type="Microsoft.TeamFoundation.TeamFoundationTextWriterTraceListener,Microsoft.TeamFoundation.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" initializeData="c:\logs\TFSBuildServiceHost.exe.log" />
         <remove name="Default" />
            </listeners>
        </trace>
    </system.diagnostics>
</configuration>

3. Create a new directory named c:\logs and ensure that the account under which the service Visual Studio Team Foundation Build Service Host has write permission on c:\logs.

4. Restart the build controller/agent service (net stop tfsbuildservicehost & net start tfsbuildservicehost).

After this a log file named TFSBuildServiceHost.exe.log should get generated in c:\logs directory.