using System.Linq;
using Microsoft.AspNetCore.Http;
using Serilog;
namespace API.Logging;
public static class LogEnricher
{
///
/// Enriches the HTTP request log with additional data via the Diagnostic Context
///
/// The Serilog diagnostic context
/// The current HTTP Context
public static void EnrichFromRequest(IDiagnosticContext diagnosticContext, HttpContext httpContext)
{
diagnosticContext.Set("ClientIP", httpContext.Connection.RemoteIpAddress?.ToString());
diagnosticContext.Set("UserAgent", httpContext.Request.Headers["User-Agent"].FirstOrDefault());
diagnosticContext.Set("Path", httpContext.Request.Path);
}
}