All Projects → mo-esmp → serilog-enrichers-clientinfo

mo-esmp / serilog-enrichers-clientinfo

Licence: MIT license
Enrich logs with client IP and UserAgent.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to serilog-enrichers-clientinfo

Aspnetcorehybridflowwithapi
ASP.NET Core MVC application using API, OpenID Connect Hybrid flow , second API, Code Flow with PKCE
Stars: ✭ 127 (+202.38%)
Mutual labels:  asp-net-core, asp-net-mvc
PersianDataAnnotations
PersianDataAnnotations is ASP.NET Core MVC & ASP.NET MVC Custom Localization DataAnnotations (Localized MVC Errors) for Persian(Farsi) language - فارسی سازی خطاهای اعتبارسنجی توکار ام.وی.سی. و کور.ام.وی.سی. برای نمایش اعتبار سنجی سمت کلاینت
Stars: ✭ 38 (-9.52%)
Mutual labels:  asp-net-core, asp-net-mvc
Kodkod
https://github.com/alirizaadiyahsi/Nucleus Web API layered architecture startup template with ASP.NET Core 2.1, EF Core 2.1 and Vue Client
Stars: ✭ 45 (+7.14%)
Mutual labels:  serilog, asp-net-core
Recaptcha Net
reCAPTCHA for .NET library lets you easily use Google's reCAPTCHA in an ASP.NET Web Forms / MVC / ASP.NET Core application.
Stars: ✭ 116 (+176.19%)
Mutual labels:  asp-net-core, asp-net-mvc
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (+107.14%)
Mutual labels:  asp-net-core, asp-net-mvc
Recaptcha.aspnetcore
Google reCAPTCHA v2/v3 for .NET Core 3.x
Stars: ✭ 122 (+190.48%)
Mutual labels:  asp-net-core, asp-net-mvc
DNZ.SEOChecker
SEO Checker and Recommander Plugin (like wordpress Yoast) for ASP.NET Core.
Stars: ✭ 18 (-57.14%)
Mutual labels:  asp-net-core, asp-net-mvc
Aspnetcore.services
Examples for ASP.NET Core webservices
Stars: ✭ 59 (+40.48%)
Mutual labels:  asp-net-core, asp-net-mvc
Cake-Shop
A sample Cake Shop Website built with ASP.NET Core (Multi-Page Application)
Stars: ✭ 44 (+4.76%)
Mutual labels:  asp-net-core, asp-net-mvc
AspNetCore-Dynamic-Permission
Dynamic Permission Samples in ASP.NET Core and ASP.NET MVC 5.
Stars: ✭ 19 (-54.76%)
Mutual labels:  asp-net-core, asp-net-mvc
Puck Core
Open source, cross platform .NET Core CMS. Fast, scalable, code-first, unobtrusive and extensible with powerful querying and Lucene integration.
Stars: ✭ 115 (+173.81%)
Mutual labels:  asp-net-core, asp-net-mvc
PoShLog
🔩 PoShLog is PowerShell cross-platform logging module. It allows you to log structured event data into console, file and much more places easily. It's built upon great C# logging library Serilog - https://serilog.net/
Stars: ✭ 108 (+157.14%)
Mutual labels:  serilog, enrichers
Accesscontrolhelper
AccessControlHelper for asp.net mvc and asp.net core, strategy based authorization
Stars: ✭ 71 (+69.05%)
Mutual labels:  asp-net-core, asp-net-mvc
CleanArchitecture-Template
This is a solution template for Clean Architecture and CQRS implementation with ASP.NET Core.
Stars: ✭ 60 (+42.86%)
Mutual labels:  serilog, asp-net-core
Dotnetpaging
Data paging with ASP.NET and ASP.NET Core
Stars: ✭ 70 (+66.67%)
Mutual labels:  asp-net-core, asp-net-mvc
identityazuretable
This project provides a high performance cloud solution for ASP.NET Identity Core using Azure Table storage replacing the Entity Framework / MSSQL provider.
Stars: ✭ 97 (+130.95%)
Mutual labels:  asp-net-core, asp-net-mvc
X.pagedlist
Library for easily paging through any IEnumerable/IQueryable in ASP.NET/ASP.NET Core
Stars: ✭ 625 (+1388.1%)
Mutual labels:  asp-net-core, asp-net-mvc
Csla
A home for your business logic in any .NET application.
Stars: ✭ 865 (+1959.52%)
Mutual labels:  asp-net-core, asp-net-mvc
MvcSimplePager
Simple,lightweight,easy to expand pager for asp.net mvc and asp.net core,针对asp.net mvc 和 asp.net core 设计的通用、扩展性良好的轻量级分页扩展
Stars: ✭ 13 (-69.05%)
Mutual labels:  asp-net-core, asp-net-mvc
DNZ.MvcComponents
A set of useful UI-Components (HtmlHelper) for ASP.NET Core MVC based-on Popular JavaScript Plugins (Experimental project).
Stars: ✭ 25 (-40.48%)
Mutual labels:  asp-net-core, asp-net-mvc

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();
            // ...
        }
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].