/

ASP.NET Core Integration

ByteHide Logger provides seamless integration with ASP.NET Core applications, automatically capturing HTTP requests, responses, and unhandled exceptions with minimal setup.

Installation

Install the ASP.NET Core integration package:

dotnet add package Bytehide.Logger.AspNetCore

Basic Configuration

Add ByteHide Logger to your ASP.NET Core application in Program.cs:

using Bytehide.Logger.AspNetCore.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Add ByteHide Logger
builder.Services.AddBytehideLogging(options => {
    options.ProjectToken = "your-project-token";
});

var app = builder.Build();

// Add ByteHide middleware
app.UseBytehideLogging();

app.Run();

Configuration Options

Basic Options

builder.Services.AddBytehideLogging(options => {
    // Required
    options.ProjectToken = "your-project-token";
    
    // HTTP Logging
    options.CaptureHttpRequests = true;    // Log incoming requests
    options.CaptureHttpResponses = true;   // Log responses with timing
    
    // Privacy
    options.LogIpAddress = false;          // Don't log client IPs
    options.ExcludedHeaders = new[] {      // Skip sensitive headers
        "Authorization", "Cookie", "X-API-Key"
    };
    
    // Integration
    options.ReplaceDefaultLogger = true;   // Use as ILogger provider
    options.LogLevel = LogLevel.Info;      // Minimum log level
});

File Logging

builder.Services.AddBytehideLogging(
    options => {
        options.ProjectToken = "your-project-token";
    },
    logSettings => {
        // Enable file logging
        logSettings.Persist = true;
        logSettings.FilePath = "logs/app.log";
        logSettings.RollingInterval = RollingInterval.Day;
    }
);

Features

Automatic HTTP Logging

// No additional code needed - automatically logs:
// - Request method, path, headers
// - Response status, timing
// - Unhandled exceptions

Custom Logging

[ApiController]
public class OrdersController : ControllerBase
{
    [HttpPost]
    public async Task<ActionResult> CreateOrder(Order order)
    {
        Log.WithMetadata("orderId", order.Id)
           .WithTags("api", "orders")
           .Info("Creating new order");
        
        try
        {
            await _orderService.CreateAsync(order);
            return Ok();
        }
        catch (Exception ex)
        {
            Log.Error("Order creation failed", ex);
            return StatusCode(500);
        }
    }
}

Middleware Position

Position the middleware correctly in your pipeline:

// Log all requests (including static files)
app.UseBytehideLogging();
app.UseStaticFiles();
app.UseRouting();

// Or log only authenticated requests
app.UseAuthentication();
app.UseAuthorization();
app.UseBytehideLogging();

Options Reference

OptionTypeDefaultDescription
ProjectTokenstringnullYour ByteHide project token
CaptureHttpRequestsbooltrueLog incoming HTTP requests
CaptureHttpResponsesbooltrueLog responses with timing
LogIpAddressboolfalseInclude client IP addresses
ExcludedHeadersstring[]["Authorization", "Cookie"]Headers to exclude from logs
ReplaceDefaultLoggerboolfalseUse as ILogger provider
LogLevelLogLevelWarnMinimum log level

Next Steps

Previous
Security Settings