HttpClientToCurlLogger 1.2.2

dotnet add package HttpClientToCurlLogger --version 1.2.2
                    
NuGet\Install-Package HttpClientToCurlLogger -Version 1.2.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HttpClientToCurlLogger" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HttpClientToCurlLogger" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="HttpClientToCurlLogger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HttpClientToCurlLogger --version 1.2.2
                    
#r "nuget: HttpClientToCurlLogger, 1.2.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package HttpClientToCurlLogger@1.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HttpClientToCurlLogger&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=HttpClientToCurlLogger&version=1.2.2
                    
Install as a Cake Tool

HttpClientToCurlLogger

NuGet License: MIT

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

  1. Disable in Production - Only enable logging in development/staging environments
  2. Sensitive Data - Be aware that headers and body content are logged (including auth tokens)
  3. 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

Reza Ghasemi

Repository

https://github.com/vamcan/HttpClientToCurlLogger

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.2 125 4/13/2026
1.2.1 103 4/13/2026
1.2.0 108 4/13/2026
1.1.1 96 4/13/2026
1.1.0 98 4/13/2026
1.0.0 1,960 2/7/2025