You can use the SendingRequest2, ReceivingResponse event to trace the out going OData request in client side. see the below example for more detail.
using Microsoft.OData.Client;
using Simple.OData.Client;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ODataClientApp
{
class Program
{
private static string fileName = "TraceLog.log";
private static Default.Container container;
static void Main(string[] args)
{
try
{
var uri = "http://localhost:32097/odata";
container = new Default.Container(new Uri(uri));
container.SendingRequest2 += Container_SendingRequest2;
container.ReceivingResponse += Container_ReceivingResponse;
var moviles = container.Movies.Execute().ToList();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
private static void Container_SendingRequest2(object sender, Microsoft.OData.Client.SendingRequest2EventArgs e)
{
var request = e.RequestMessage as HttpWebRequestMessage;
var x = container;
var url = request.Url.AbsoluteUri;
var method = request.Method;
var authenticationLevel = request.HttpWebRequest.AuthenticationLevel;
var impersonationLevel = request.HttpWebRequest.ImpersonationLevel.ToString();
var headers = request.Headers;
var sb = new StringBuilder();
sb.AppendLine(DateTime.Now.ToString() + "------------------------------SendingRequest2 Begin---------------------------");
sb.AppendLine("Url:" + url);
sb.AppendLine("Method:" + method);
sb.AppendLine("Authentication Level:" + authenticationLevel);
sb.AppendLine("Impersonation Level:" + impersonationLevel);
sb.AppendLine();
sb.AppendLine("Header Info:-");
foreach (var header in headers)
{
sb.AppendFormat("{0}:{1}", header.Key, header.Value);
sb.AppendLine();
}
sb.AppendLine(DateTime.Now.ToString() + "------------------------------SendingRequest2 End-----------------------------");
File.AppendAllText(fileName, sb.ToString());
}
private static void Container_ReceivingResponse(object sender, Microsoft.OData.Client.ReceivingResponseEventArgs e)
{
var response = e.ResponseMessage as HttpWebResponseMessage;
var statusCode = response.StatusCode.ToString();
var headers = response.Headers;
var sb = new StringBuilder();
sb.AppendLine(DateTime.Now.ToString() + "------------------------------ReceivingResponse Begin-------------------------");
sb.AppendLine("Status Code:" + statusCode);
sb.AppendLine();
sb.AppendLine("Header Info:-");
foreach (var header in headers)
{
sb.AppendFormat("{0}:{1}", header.Key, header.Value);
sb.AppendLine();
}
sb.AppendLine(DateTime.Now.ToString() + "------------------------------ReceivingResponse End---------------------------");
File.AppendAllText(fileName, sb.ToString());
}
}
}