Serilog.Enrichers.ClientInfo 1.1.4

.NET Standard 2.0 .NET Framework 4.5.2
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();
            // ...
        }
    }
}
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net452 net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (17)

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 576,805 8/22/2021
1.1.4-dev01 150 8/22/2021
1.1.3 588,154 12/18/2020
1.1.2 102,400 12/7/2020
1.1.1 262 12/6/2020
1.1.0 83,040 4/23/2020
1.0.0 10,058 1/5/2020