Elastic.CommonSchema.Serilog.Sink 8.4.0-alpha4

Prefix Reserved
This is a prerelease version of Elastic.CommonSchema.Serilog.Sink.
dotnet add package Elastic.CommonSchema.Serilog.Sink --version 8.4.0-alpha4                
NuGet\Install-Package Elastic.CommonSchema.Serilog.Sink -Version 8.4.0-alpha4                
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.Sink" Version="8.4.0-alpha4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Elastic.CommonSchema.Serilog.Sink --version 8.4.0-alpha4                
#r "nuget: Elastic.CommonSchema.Serilog.Sink, 8.4.0-alpha4"                
#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.Sink as a Cake Addin
#addin nuget:?package=Elastic.CommonSchema.Serilog.Sink&version=8.4.0-alpha4&prerelease

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

Elastic.CommonSchema.Serilog.Sink

A Serilog sink that writes logs directly to Elasticsearch or Elastic Cloud

Example

There's a few ways that you can extend a Serilog LoggerConfiguration:

Log.Logger = new LoggerConfiguration()
	.MinimumLevel.Debug()
	.Enrich.FromLogContext()

NOTE: Don't forget we also publish an Elastic.Apm.SerilogEnricher for the Elastic APM Agent!

Writing to Elasticsearch

.WriteTo.Elasticsearch(new [] { new Uri("http://localhost:9200" )}, opts =>
{
	opts.DataStream = new DataStreamName("logs", "console-example", "demo");
	opts.BootstrapMethod = BootstrapMethod.Failure;
	opts.ConfigureChannel = channelOpts =>
	{
		channelOpts.BufferOptions = new BufferOptions 
		{ 
			ConcurrentConsumers = 10 
		};
	};
})

Writing to Elastic Cloud:

.WriteTo.ElasticCloud("cloudId", "cloudUser", "cloudPass", opts =>

opts is an instance of ElasticsearchSinkOptions with the following options

Option Description
Transport An instance of Elastic.Transport that dictates where and how wer are communicating to. Defaults to http://localhost:9200
DataStream Where to write data, defaults to the logs-dotnet-default datastream.
BootstrapMethod Wheter the sink should attempt to install component and index templates to ensure the datastream has ECS mappings. Can be be either None (the default), Silent (attempt but fail silently), Failure (attempt and fail with exceptions if bootstrapping fails).
TextFormatting Allows explicit control of over the EcsTextFormatterConfiguration used to emit ECS json documents. See Elastic.CommonSchema.Serilog for available options.
ConfigureChannel A callback receiving the DatastreamChannelOptions which allows you to control sizing, backpressure etc. See Elastic.Ingest.Elasticsearch for more information.

Note that you can also pass ElasticsearchSinkOptions directly

.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(client.Transport)

This allows you to reuse the Transport used by the Elasticsearch Client for instance.

ECS Aware Message Templates

This sink by proxy of its formatter 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.

Comparison with Serilog.Sinks.Elasticsearch

  • Serilog.Sinks.Elasticsearch is an amazing community led sink that has a ton of options and works against older Elasticsearch versions < 8.0.
  • Serilog.Sinks.Elasticsearch is unofficially supported by Elastic with some of the .NET team helping to maintain it.
  • Elastic.CommonSchema.Serilog.Sink is officially supported by Elastic and was purposely build to adhere to newer best practices around logging, datastreams and ILM.
  • Elastic.CommonSchema.Serilog.Sink is purposely build to have fewer configuration options and be more prescriptive than Serilog.Sinks.Elasticsearch.
    • That is not to say there aren't plenty of configuration hooks in Elastic.CommonSchema.Serilog.Sink
Notable absent features:
  • Elastic.CommonSchema.Serilog.Sink only works with Elasticsearch 8.x and up.
    • This is because the bootrapping (BootstrapMethod) attempts to load templates build for Elasticsearch 8.0 and up.
  • Elastic.CommonSchema.Serilog.Sink has only one way it emits data to Elasticsearch confirming to the ecs-logging specification
    • That doesn't mean you can not introduce your own additional properties though.
  • Elastic.CommonSchema.Serilog.Sink has no durable mode.

If you miss a particular feature from Serilog.Sinks.Elasticsearch in Elastic.CommonSchema.Serilog.Sink please open a feature request! We'd love to grow this sink organically moving forward.

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 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.4.0-alpha4 496 3/28/2023
8.4.0-alpha3 98 3/15/2023
8.4.0-alpha2 113 3/1/2023
8.4.0-alpha1 266 2/20/2023