Elastic.CommonSchema.Serilog 8.4.0-alpha1

Prefix Reserved
This is a prerelease version of Elastic.CommonSchema.Serilog.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Elastic.CommonSchema.Serilog --version 8.4.0-alpha1                
NuGet\Install-Package Elastic.CommonSchema.Serilog -Version 8.4.0-alpha1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.4.0-alpha1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Elastic.CommonSchema.Serilog --version 8.4.0-alpha1                
#r "nuget: Elastic.CommonSchema.Serilog, 8.4.0-alpha1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Elastic.CommonSchema.Serilog as a Cake Addin
#addin nuget:?package=Elastic.CommonSchema.Serilog&version=8.4.0-alpha1&prerelease

// Install Elastic.CommonSchema.Serilog as a Cake Tool
#tool nuget:?package=Elastic.CommonSchema.Serilog&version=8.4.0-alpha1&prerelease                

Elastic Common Schema Serilog Text Formatter

This ITextFormatter implementation formats a Serilog event into a JSON representation that adheres to the Elastic Common Schema specification.

Packages

The .NET assemblies are published to NuGet under the package name Elastic.CommonSchema.Serilog

How to Enable

var logger = new LoggerConfiguration()
                .WriteTo.Console(new EcsTextFormatter())
                .CreateLogger();

In the code snippet above new EcsTextFormatter() enables the text formatter and instructs Serilog to format the event as JSON. The sample above uses the Console sink, but you are free to use any sink of your choice, perhaps consider using a filesystem sink and Elastic Filebeat for durable and reliable ingestion.

In ASP.NET (core) applications

.UseSerilog((ctx, config) =>
{
	// Ensure HttpContextAccessor is accessible
	var httpAccessor = ctx.Configuration.Get<HttpContextAccessor>();

	config
		.ReadFrom.Configuration(ctx.Configuration)
		.Enrich.WithEcsHttpContext(httpAccessor)
		.WriteTo.Async(a => a.Console(new EcsTextFormatter()));
})

The WithEcsHttpContext ensures logs will be enriched with HttpContext data.

An example of the output is given below:

{
  "@timestamp": "2019-11-22T14:59:02.5903135+11:00",
  "log.level": "Information",
  "message": "Log message",
  "ecs": {
    "version": "1.4.0"
  },
  "event": {
    "severity": 0,
    "timezone": "AUS Eastern Standard Time",
    "created": "2019-11-22T14:59:02.5903135+11:00"
  },
  "log": {
    "logger": "Elastic.CommonSchema.Serilog"
  },
  "process": {
    "thread": {
      "id": 1
    },
    "executable": "System.Threading.ExecutionContext"
  }
}

Configuration

Option Description
MapCurrentThead true map ecs.process by looking up the Process from the current thread
MapHttpAdapter null a way to map HttpContextAccessor to ECS fields.
LogEventsPropertiesToFilter A Set<string> of properties that should not be emitted as labels.* or metadata.*
MapCustom A Func that allows you to mutate the EcsDocument before its fully converted.

ECS Aware Message Templates

This formatter also allows you to set ECS fields directly from the message template using properties that adhere to the https://messagetemplates.org/ format.

The available ECS message template properties are listed under LogTemplateProperties.* e.g LogTemplateProperties.TraceId

Log.Information("The time is {TraceId}", "my-trace-id");

Will override trace.id on the resulting ECS json document.

This software is Copyright (c) 2014-2020 by Elasticsearch BV.

This is free software, licensed under: The Apache License Version 2.0.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (20)

Showing the top 5 NuGet packages that depend on Elastic.CommonSchema.Serilog:

Package Downloads
Serilog.Sinks.Logz.Io

Serilog event sink that sends logs to Logz.io.

Elastic.Serilog.Sinks

Package Description

Sitko.Core.ElasticStack

Sitko.Core is a set of libraries to help build .NET Core applications fast

BioEngine.Extra.ElasticStack

Package Description

Elastic.Serilog.Enrichers.Web

Serilog enricher for ASP.NET (Core) to inject more data in emitted Elastic Common Schema (ECS) documents.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Elastic.CommonSchema.Serilog:

Repository Stars
jerrytang67/SoMall
社交电商商城开源项目.socail+mall即取名SoMall ,abp netcore 3.1 angular vue uni-app typescript docker mssql
damikun/trouble-training
FullStack DDD/CQRS with GraphQL workshop including distributed tracing and monitoring. This shows the configuration from React frontend to .Net backend.
sitkoru/Sitko.Core
Sitko.Core is a set of libraries to help build .NET Core applications fast
Version Downloads Last updated
8.12.3 59,078 11/26/2024
8.12.2 152,711 10/22/2024
8.12.1 212,123 10/3/2024
8.12.0 39,594 9/26/2024
8.11.1 732,618 6/10/2024
8.11.0 568,555 4/10/2024
8.6.1 1,789,541 8/3/2023
8.6.0 395,801 5/9/2023
8.4.0-alpha4 10,770 3/28/2023
8.4.0-alpha3 528 3/15/2023
8.4.0-alpha2 503 3/1/2023
8.4.0-alpha1 974 2/20/2023
1.6.0-alpha1 86,385 6/2/2021
1.5.3 7,761,324 6/1/2021
1.5.1 1,528,290 6/3/2020
1.5.0 148,411 3/30/2020
1.4.4 1,589 3/25/2020
1.4.3 5,529 3/16/2020
1.4.2 25,964 3/6/2020
1.4.1 9,643 2/26/2020
1.4.0 15,825 1/29/2020
1.4.0-beta1 855 1/7/2020