Tracing OCS components may be vital in troubleshooting various issues you may face in your deployment. On machines where you have OCS components installed, you'll typically find a tool called OCSLogger.exe which allows you to start/stop/view traces of OCS components. However, sometimes this is not enough, for instance when you see problems at the startup of a machine. It's kind of hard to run the GUI if you cannot logon yet. But you can typically run a scheduled task. Or maybe you are — just like me — more like the console guy and thus want to have a script/cmdline tool for everything.
1: <?xml version="1.0" encoding="utf-8"?>
2: <Config>
3: <!--
4: Levels:
5: TL_FATAL 1
6: TL_ERROR 2
7: TL_WARN 3
8: TL_INFO 4
9: TL_VERBOSE 5
10: TL_NOISE 6
11:
12: Flags:
13: TF_COMPONENT 0x00000001
14: TF_PROTOCOL 0x00000002
15: TF_CONNECTION 0x00000004
16: TF_SECURITY 0x00000008
17: TF_DIAG 0x00000010
18: TF_AUTH 0x00000020
19: TF_PARSE 0x00000040
20: TF_NETWORK 0x00000080
21: TF_STACKTRACE 0x00000100
22: -->
23: <Default Level="6" Flags="0xffff" />
24: <Paths Tracer="C:\Program Files\Common Files\Microsoft Communications Server 2007 R2\Tracing"
25: Etl="D:\Tracing"
26: Log="D:\Tracing"
27: TmfSearchPath="C:\Program Files\Common Files\Microsoft Communications Server 2007 R2\Tracing">
28: </Paths>
29: <Components>
30: <Component Name="LcsWMI" Enabled="no" />
31: <Component Name="LcsWMIUserServices" Enabled="no" />
32:
33: <Component Name="PowerShell" Enabled="yes" />
34:
35: <Component Name="ApplicationServer" Enabled="yes" />
36:
37: <Component Name="RgsClientsLib" Enabled="yes" />
38: <Component Name="RgsCommonLibrary" Enabled="yes" />
39: <Component Name="RgsDatastores" Enabled="yes" />
40: <Component Name="RgsDeploymentApi" Enabled="yes" />
41: <Component Name="RgsDeploymentLibrary" Enabled="yes" />
42: <Component Name="RgsDiagnostics" Enabled="yes" />
43: <Component Name="RgsHostingFramework" Enabled="yes" />
44: <Component Name="RgsMatchMakingService" Enabled="yes" />
45: </Components>
46: </Config>
I added the most importan trace levels and flags in the comment. Right now, the Default element defines the levels and flags for all components, but there's no reason why you shouldn't be able to do that per component you want to trace.
1: <#
2: .SYNOPSIS
3: Starts or Stops tracing of Office Communications Server components.
4: .DESCRIPTION
5: Starts or Stops tracing of Office Communications Server components.
6: .PARAMETER Action
7: The action to perform. Must be one of 'Start', 'Stop', 'Config' or
8: 'Format'.
9: .PARAMETER ConfigPath
10: The path to the configuration XML file. If not specified,
11: "TraceConfig.xml" is used.
12: .LINK
13: This script was originally posted to
14: http://www.cymbeline.ch/post/2009/12/11/PowerShell-Script-to-trace-OCS-Components.aspx
15: .EXAMPLE
16: .\Tracer.ps1 Start
17:
18: Starts tracing all the enabled components from the "TraceConfig.xml" file.
19: .EXAMPLE
20: .\Tracer.ps1 Stop
21:
22: Stops tracing all the enabled components from the "TraceConfig.xml" file
23: and formats the traces.
24: .EXAMPLE
25: .\Tracer.ps1 Format "MyOtherConfig.xml"
26:
27: Formats the traces of the enabled components from the "MyOtherConfig.xml"
28: file with all the settings from the "MyOtherConfig.xml" file.
29: .EXAMPLE
30: .\Tracer.ps1 Config
31:
32: Shows the configuration of the "TraceConfig.xml" file.
33: #>
34: param(
35: [Parameter(Mandatory=$true)]
36: [ValidateSet("Start", "Stop", "Config", "Format", IgnoreCase=$true)]
37: [String] $Action,
38: [String] $ConfigPath = "TraceConfig.xml"
39: )
40:
41: $configXml = ([xml](Get-Content $ConfigPath))
42: $tracerPath = $configXml.Config.Paths.Tracer
43: $etlDir = $configXml.Config.Paths.Etl
44: $logDir = $configXml.Config.Paths.Log
45: $tmfSearchPath = $configXml.Config.Paths.TmfSearchPath
46:
47: # Construct the parameters for the 'Start' command to OcsTracer.exe
48: function getStartParams()
49: {
50: $ret = @()
51:
52: $configXml.Config.Components.Component |
53: ? {$_.Enabled -eq "yes"} |
54: foreach {
55: $ret = $ret +
56: ("/Component:" + $_.Name + "," + $configXml.Config.Default.Level +
57: "," + $configXml.Config.Default.Flags + " ")
58: }
59:
60: return $ret
61: }
62:
63: # Construct the parameters for the 'Stop' command to OcsTracer.exe
64: function getStopParams()
65: {
66: $ret = @()
67:
68: $configXml.Config.Components.Component |
69: ? {$_.Enabled -eq "yes"} |
70: foreach { $ret = $ret + ("/Component:" + $_.Name) }
71:
72: return $ret
73: }
74:
75: # Format the ETL files for enabled components to a human readable format
76: function formatFiles(
77: [Parameter(Mandatory=$true)]
78: [String] $Timestamp
79: )
80: {
81: md $logDir\$timestamp -ea silentlycontinue | Out-Null
82:
83: $configXml.Config.Components.Component |
84: ? {$_.Enabled -eq "yes"} |
85: foreach {
86: $etlFile = $_.Name + ".etl";
87:
88: if (Test-Path $etlFile)
89: {
90: $logFile = $Timestamp + "\" + $Timestamp + "_" + $_.Name + ".log";
91:
92: & "$tracerPath\OcsTracer.exe" Format /LogFilePath:"$etlDir\$etlFile" /OutputFile:"$logDir\$logFile" /TmfSearchPath:"$tmfSearchPath" | Write-Verbose
93: }
94: else
95: {
96: Write-Warning "File $etlFile not found.";
97: }
98: }
99: }
100:
101: Write-Host "Using Config File: $ConfigPath"
102: $timestamp = Get-Date -format "yyyy-MM-dd_HH.mm.ss"
103:
104: if ($Action -eq "start")
105: {
106: Write-Host "Removing all .etl files ..."
107: ls $etlDir *.etl | ri
108:
109: Write-Host "Start tracing components ..."
110: $params = getStartParams
111:
112: & "$tracerPath\OcsTracer.exe" Start $params /LogFileFolder:"$etlDir" | Write-Verbose
113: }
114: elseif ($Action -eq "stop")
115: {
116: Write-Host "Stop tracing components ..."
117: $params = getStopParams
118:
119: md $logDir\$timestamp | Out-Null
120:
121: & "$tracerPath\OcsTracer.exe" Stop $params /OutputFile:"$logDir\$timestamp\$($timestamp)_All.log" /TmfSearchPath:"$tmfSearchPath" | Write-Verbose
122:
123: if (!$?)
124: {
125: rd $logDir\$timestamp | Out-Null
126: }
127: else
128: {
129: Write-Host "Sessions stopped. Start formatting ..."
130: formatFiles $timestamp
131: }
132: }
133: elseif ($Action -eq "format")
134: {
135: Write-Host "Formatting traces from ETL files ..."
136: formatFiles $timestamp
137: }
138: elseif ($Action -eq "config")
139: {
140: Write-Host "Default values"
141: Write-Host "--------------"
142: $configXml.Config.Default | ft Level,Flags
143:
144: Write-Host "Paths"
145: Write-Host "-----"
146: $configXml.Config.Paths | fl
147:
148: Write-Host "Components"
149: Write-Host "----------"
150: $configXml.Config.Components.Component | ft Name,Enabled
151: }
152: else
153: {
154: Write-Error "Unknown action."
155: }