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
Option | Type | Default | Description |
---|---|---|---|
ProjectToken | string | null | Your ByteHide project token |
CaptureHttpRequests | bool | true | Log incoming HTTP requests |
CaptureHttpResponses | bool | true | Log responses with timing |
LogIpAddress | bool | false | Include client IP addresses |
ExcludedHeaders | string[] | ["Authorization", "Cookie"] | Headers to exclude from logs |
ReplaceDefaultLogger | bool | false | Use as ILogger provider |
LogLevel | LogLevel | Warn | Minimum log level |
Next Steps
- Configuration - Set up your project token
- Exception Handling - Learn about error logging
- Fluent Syntax - Advanced logging patterns