mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-12-22 04:47:21 -05:00
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
21 lines
776 B
C#
21 lines
776 B
C#
using System.Linq;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Serilog;
|
|
|
|
namespace API.Logging;
|
|
|
|
public static class LogEnricher
|
|
{
|
|
/// <summary>
|
|
/// Enriches the HTTP request log with additional data via the Diagnostic Context
|
|
/// </summary>
|
|
/// <param name="diagnosticContext">The Serilog diagnostic context</param>
|
|
/// <param name="httpContext">The current HTTP Context</param>
|
|
public static void EnrichFromRequest(IDiagnosticContext diagnosticContext, HttpContext httpContext)
|
|
{
|
|
diagnosticContext.Set("ClientIP", httpContext.Connection.RemoteIpAddress?.ToString());
|
|
diagnosticContext.Set("UserAgent", httpContext.Request.Headers.UserAgent.FirstOrDefault());
|
|
diagnosticContext.Set("Path", httpContext.Request.Path);
|
|
}
|
|
}
|