A lightweight .NET library that automatically logs all HttpClient requests as cURL commands. Perfect for debugging, testing, and sharing API requests during development.
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+
Install via NuGet Package Manager:
dotnet add package HttpClientToCurlLoggerOr via Package Manager Console:
Install-Package HttpClientToCurlLoggerAdd 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>();
}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();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"
================================================================================
| 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) |
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
});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);
});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>).
- .NET Standard 2.0 or higher
- Microsoft.Extensions.Http 2.1.0+
- Microsoft.Extensions.Logging.Abstractions 2.1.0+
- .NET Core 2.0+
- .NET 5, 6, 7, 8+
- .NET Framework 4.6.1+
- 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
- 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
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.