mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-03-10 03:55:45 -04:00
Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com> Co-authored-by: Joe Milazzo <josephmajora@gmail.com>
21 lines
786 B
C#
21 lines
786 B
C#
using System.Linq;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Serilog;
|
|
|
|
namespace Kavita.Server.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);
|
|
}
|
|
}
|