-
Notifications
You must be signed in to change notification settings - Fork 199
How to capture SOAP messages
When debugging Ads API calls, one important resource is the SOAP messages you send to the server. Here are some ways to capture the SOAP logs.
The Ads API .NET client library logs SOAP requests through System.Trace
. You can control the settings through your application’s App.config / Web.config
files. An example default config file is shown below:
<system.diagnostics>
<sources>
<source name="AdsClientLibs.DeprecationMessages"
switchName="AdsClientLibs.DeprecationMessages"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="myListener" type="System.Diagnostics.EventLogTraceListener"
initializeData="Application"/>
</listeners>
</source>
<source name="AdsClientLibs.DetailedRequestLogs"
switchName="AdsClientLibs.DetailedRequestLogs"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="detailedRequestLogListener" type="System.Diagnostics.ConsoleTraceListener"
initializeData="true"/>
<!-- Use the following to log to file. Modify the initializeData
attribute to control the path to the detailed request log file.
<add name="detailedRequestLogListener" type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\Logs\AdManager\detailed_logs.log"/>
-->
<remove name="Default"/>
</listeners>
</source>
<source name="AdsClientLibs.SummaryRequestLogs" switchName="AdsClientLibs.SummaryRequestLogs"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="summaryRequestLogListener" type="System.Diagnostics.ConsoleTraceListener"
initializeData="true"/>
<!-- Use the following to log to file. Modify the initializeData
attribute to control the path to the summary request log file.
<add name="summaryRequestLogListener" type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\Logs\AdManager\summary_logs.log"/>
-->
<remove name="Default"/>
</listeners>
</source>
</sources>
<switches>
<!-- Use this trace switch to control the deprecation trace messages
written by Ads* .NET libraries. The default is level is set to
Warning. To disable all messages, set this value to Off. See
http://msdn.microsoft.com/en-us/library/system.diagnostics.sourcelevels.aspx
for all possible values this key can take. -->
<add name="AdsClientLibs.DeprecationMessages" value="Warning" />
<!-- Use this trace switch to control the detailed request logs written by Ads*
.NET libraries. The default level is set to Off. Logs are generated at
both the Error and Information levels. -->
<add name="AdsClientLibs.DetailedRequestLogs" value="Off" />
<!-- Use this trace switch to control the summary request logs written by
Ads* .NET libraries. The default level is set to Off. Logs are
generated at both the Error and Information levels. -->
<add name="AdsClientLibs.SummaryRequestLogs" value="Off" />
</switches>
<trace autoflush="true" />
</system.diagnostics>
Logging can be enabled or disabled by editing the value attribute of the AdsClientLibs.DetailedRequestLogs
and AdsClientLibs.SummaryRequestLogs
trace switches. See this MSDN article for a list of all possible switch values, but note that only a subset of these values are used by this library:
Value | Impact on logging |
---|---|
Off |
Nothing will be logged. |
Error |
Errors will be logged. |
Information |
Errors and debugging information will be logged. |
To enable the most verbose logging (Information
), you would make the following changes:
<add name="AdsClientLibs.DetailedRequestLogs" value="Information"/>
<add name="AdsClientLibs.SummaryRequestLogs" value="Information"/>
See this wiki article for more details on App.config
.
You can also configure logging at runtime as follows:
TraceUtilities.Configure(TraceUtilities.DETAILED_REQUEST_LOGS_SOURCE,
"C:\\Logs\\simply_detailed_logs.log", SourceLevels.All);
TraceUtilities.Configure(TraceUtilities.SUMMARY_REQUEST_LOGS_SOURCE,
"C:\\Logs\\simply_summary_logs.log", SourceLevels.All);
You can use Fiddler, an HTTP(s) proxy to capture traffic from the Ads API .NET client library. Once you launch Fiddler, it will start acting as an HTTP(s) proxy server, running on localhost:8888. To capture HTTPS traffic, you need to turn on HTTPS decryption. This can be done by following the instructions on http://www.fiddler2.com/Fiddler/help/OptionsUI.asp.
Now, set the ProxyServer
configuration setting in your application’s App.config / Web.config
to http://localhost:8888 and run your application.
Note: Proxy settings don't work on .NET Core 2.0. See https://github.com/googleads/googleads-dotnet-lib/issues/133
Options 1 and 2 are good for most situations, but if you absolutely need the raw logs for the HTTP(S) calls you make, then you can use System.Net
tracing options. You need to add the following lines to your App.config
to achieve this:
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.Net">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Cache">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add
name="System.Net"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="System.Net.trace.log"/>
</sharedListeners>
<switches>
<add name="System.Net" value="Verbose" />
<add name="System.Net.Sockets" value="Verbose" />
<add name="System.Net.Cache" value="Verbose" />
</switches>
</system.diagnostics>
When you run your application, the detailed trace will be written to System.Net.trace.log
.