HttpClientToCurlLogger 1.2.2
dotnet add package HttpClientToCurlLogger --version 1.2.2
NuGet\Install-Package HttpClientToCurlLogger -Version 1.2.2
<PackageReference Include="HttpClientToCurlLogger" Version="1.2.2" />
<PackageVersion Include="HttpClientToCurlLogger" Version="1.2.2" />
<PackageReference Include="HttpClientToCurlLogger" />
paket add HttpClientToCurlLogger --version 1.2.2
#r "nuget: HttpClientToCurlLogger, 1.2.2"
#:package HttpClientToCurlLogger@1.2.2
#addin nuget:?package=HttpClientToCurlLogger&version=1.2.2
#tool nuget:?package=HttpClientToCurlLogger&version=1.2.2
HttpClientToCurlLogger
A lightweight .NET library that automatically logs all HttpClient requests as cURL commands. Perfect for debugging, testing, and sharing API requests during development.
Features
Automatic Logging - Captures all HttpClient requests automatically
cURL Format - Generates ready-to-use cURL commands
Easy Integration - Single line of configuration
Toggle On/Off - Enable or disable logging via configuration
Multiple Clients - Works with all registered HttpClient instances
Headers & Body - Includes headers and request body in the cURL output
.NET Standard 2.0 - Compatible with .NET Core 2.0+ and .NET Framework 4.6.1+
Installation
Install via NuGet Package Manager:
dotnet add package HttpClientToCurlLogger
Or via Package Manager Console:
Install-Package HttpClientToCurlLogger
Usage
Basic Setup
Add the following to your Startup.cs or Program.cs:
using HttpClientToCurlLogger;
public void ConfigureServices(IServiceCollection services)
{
// Add cURL logging
services.AddCurlLogging(options =>
{
options.EnableLogging = true; // Set to false to disable
});
// Register your HttpClient(s)
services.AddHttpClient("MyClient");
services.AddHttpClient<IMyService, MyService>();
}
ASP.NET Core Minimal API (.NET 6+)
using HttpClientToCurlLogger;
var builder = WebApplication.CreateBuilder(args);
// Add cURL logging
builder.Services.AddCurlLogging(options =>
{
options.EnableLogging = true;
});
// Register HttpClient
builder.Services.AddHttpClient("MyClient");
var app = builder.Build();
app.Run();
Example Output
When you make an HTTP request:
var client = httpClientFactory.CreateClient("MyClient");
await client.PostAsJsonAsync("https://api.example.com/users", new { name = "John" });
You'll see in your logs:
curl -X POST -H "Content-Type: application/json; charset=utf-8" -d "{\"name\":\"John\"}" "https://api.example.com/users"
You can copy this cURL command directly to your terminal or Postman!
The output will look like this:
================================================================================
cURL Command (copy-paste ready):
================================================================================
curl -X POST \
-H "ApiKey: your-api-key" \
-H "Content-Type: application/json; charset=utf-8" \
-d "{\"name\":\"John\"}" \
"https://api.example.com/users"
================================================================================
Configuration Options
| Property | Type | Default | Description |
|---|---|---|---|
EnableLogging |
bool |
false |
Enable or disable cURL logging |
UseMultiLineFormat |
bool |
true |
Format curl command with line breaks for better readability |
UseFormattedOutput |
bool |
true |
Add separators and headers around the curl command |
UseConsoleOutput |
bool |
false |
Write directly to Console instead of ILogger (recommended for structured logging) |
Advanced Configuration
services.AddCurlLogging(options =>
{
options.EnableLogging = true;
options.UseMultiLineFormat = true; // Multi-line format with \ continuation
options.UseFormattedOutput = true; // With separators and headers
options.UseConsoleOutput = false; // Use ILogger (default)
});
For Structured Logging (Serilog, NLog with JSON formatters):
If you're using structured logging that outputs JSON (like Serilog with JSON formatter or Elastic.CommonSchema.Serilog), enable UseConsoleOutput to bypass the logger and write directly to console for readable output:
services.AddCurlLogging(options =>
{
options.EnableLogging = true;
options.UseMultiLineFormat = true; // Multi-line format
options.UseFormattedOutput = true; // With separators
options.UseConsoleOutput = true; // Direct console output (bypasses structured logging)
});
For compact single-line output (useful for simple logging):
services.AddCurlLogging(options =>
{
options.EnableLogging = true;
options.UseMultiLineFormat = false; // Single line
options.UseFormattedOutput = false; // No separators
});
Environment-Based Configuration
You can control logging based on environment:
services.AddCurlLogging(options =>
{
options.EnableLogging = builder.Environment.IsDevelopment();
});
Or use configuration files (appsettings.json):
{
"CurlLogging": {
"EnableLogging": true,
"UseMultiLineFormat": true,
"UseFormattedOutput": true,
"UseConsoleOutput": true
}
}
services.AddCurlLogging(options =>
{
configuration.GetSection("CurlLogging").Bind(options);
});
How It Works
The library uses an IHttpMessageHandlerBuilderFilter to automatically inject a DelegatingHandler into all registered HttpClient instances. This handler intercepts requests and logs them as cURL commands using the configured logger (typically ILogger<T>).
Requirements
- .NET Standard 2.0 or higher
- Microsoft.Extensions.Http 2.1.0+
- Microsoft.Extensions.Logging.Abstractions 2.1.0+
Supported Frameworks
- .NET Core 2.0+
- .NET 5, 6, 7, 8+
- .NET Framework 4.6.1+
Use Cases
- Debugging - Quickly see what requests your application is making
- Testing - Copy cURL commands to test APIs manually
- Documentation - Share API request examples with your team
- Troubleshooting - Diagnose integration issues with external APIs
Best Practices
- Disable in Production - Only enable logging in development/staging environments
- Sensitive Data - Be aware that headers and body content are logged (including auth tokens)
- Performance - Minimal overhead, but consider disabling for high-throughput scenarios
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.0)
- Microsoft.Extensions.Http (>= 2.1.0)
- Microsoft.Extensions.Logging.Abstractions (>= 2.1.0)
- Microsoft.Extensions.Options (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.