Serilog.Enrichers.ClientInfo 1.1.4

Install-Package Serilog.Enrichers.ClientInfo -Version 1.1.4
dotnet add package Serilog.Enrichers.ClientInfo --version 1.1.4
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Enrichers.ClientInfo --version 1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Serilog.Enrichers.ClientInfo, 1.1.4"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Serilog.Enrichers.ClientInfo as a Cake Addin
#addin nuget:?package=Serilog.Enrichers.ClientInfo&version=1.1.4

// Install Serilog.Enrichers.ClientInfo as a Cake Tool
#tool nuget:?package=Serilog.Enrichers.ClientInfo&version=1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

serilog-enrichers-clientinfo NuGet

Enrich logs with client IP and UserAgent.

Install the Serilog.Enrichers.ClientInfo NuGet package

Install-Package Serilog.Enrichers.ClientInfo

or

dotnet add package Serilog.Enrichers.ClientInfo

Apply the enricher to your LoggerConfiguration in code:

Log.Logger = new LoggerConfiguration()
    .Enrich.WithClientIp()
    .Enrich.WithClientAgent()
    // ...other configuration...
    .CreateLogger();

or in appsettings.json file:

{
  "Serilog": {
    "MinimumLevel": "Debug",
    "Using":  [ "Serilog.Enrichers.ClientInfo" ],
    "Enrich": [ "WithClientIp", "WithClientAgent"],
    "WriteTo": [
      { "Name": "Console" }
    ]
  }
}

The WithClientIp() enricher will add a ClientIp property and the WithClientAgent() enricher will add a ClientAgent property to produced events.

Installing into an ASP.NET Core Web Application

You need to register the IHttpContextAccessor singleton so the enrichers have access to the requests HttpContext to extract client IP and client agent. This is what your Startup class should contain in order for this enricher to work as expected:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;

namespace MyWebApp
{
    public class Startup
    {
        public Startup()
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3} {ClientIp} {ClientAgent}] {Message:lj}{NewLine}{Exception}")
                .Enrich.WithClientIp()
                .Enrich.WithClientAgent()
                .CreateLogger();
        }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // ...
            services.AddHttpContextAccessor();
            // ...
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            // ...
            loggerFactory.AddSerilog();
            // ...
        }
    }
}

NuGet packages (11)

Showing the top 5 NuGet packages that depend on Serilog.Enrichers.ClientInfo:

Package Downloads
KAM.Aether.SharedLibraries

KAM.Aether.SharedLibraries and SharedModels

Kourosh.Aether.SharedLibraries

Kourosh.Aether.SharedLibraries

CodeZero

CodeZero is a set of common implementations to help you implementing Clean Architecture, DDD, CQRS, Specification Patterns and another facilities for new modern web applications is an open-source project written in .NET Core.

WGM.Infrastructure.Core

Package Description

NetCoreCleanArchitecture.WebHosting

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.4 116,799 8/22/2021
1.1.4-dev01 107 8/22/2021
1.1.3 390,710 12/18/2020
1.1.2 66,799 12/7/2020
1.1.1 217 12/6/2020
1.1.0 67,546 4/23/2020
1.0.0 8,762 1/5/2020