Monday, 8 April 2024

OrderCloud .NET SDK logging

Just thought I'd drop a handy little piece of code for when you're running / debugging the OrderCloud .NET SDK locally. If you ever need to see which HTTP calls are being made, and any info about the request URL, body, response, or more importantly errors, you can just add this little snippet to your Program.cs after var app = builder.Build();

FlurlHttp.Configure(settings => settings.BeforeCall = (FlurlCall call) =>
{
app.Logger.LogInformation($"Calling {call.Request.Url} with {call.RequestBody}");
});
FlurlHttp.Configure(settings => settings.OnError = (FlurlCall call) =>
{
app.Logger.LogError(call.Exception, $"Error calling {call.Request.Url}");
});
view raw Program.cs hosted with ❤ by GitHub

Hope this helps someone! Enjoy :)