Skip to main content

Enrich Serilog log messages with APM TraceId and TransactionId.

Total Downloads
23.0M
23,013,428
Published
Aug 13, 2025
1y ago

Get Started

dotnet add package Elastic.Apm.SerilogEnricher --version 9.0.0
ProductVersions
.NET
net8.0
.NET Standard
netstandard2.0
Other
.NETFramework4.6.2

README

Elastic APM Serilog Enricher

This enricher adds the transaction id and trace id to every Serilog log message that is created during a transaction.

Packages

The .NET assemblies are published to NuGet under the package name Elastic.Apm.SerilogEnricher

How to Enable

var logger = new LoggerConfiguration()
   .Enrich.WithElasticApmCorrelationInfo()
   .WriteTo.Console(outputTemplate: "[{ElasticApmTraceId} {ElasticApmTransactionId} {ElasticApmSpanId} {Message:lj} {NewLine}{Exception}")
   .CreateLogger();

In the code snippet above Enrich.WithElasticApmCorrelationInfo() enables the enricher from this project, which will set 3 properties for log lines that are created during a transaction:

  • ElasticApmTraceId
  • ElasticApmTransactionId
  • ElasticApmSpanId

These two properties are printed to the Console using the outputTemplate parameter, of course they can be used with any sink, you could consider using a filesystem sink and Elastic Filebeat for durable and reliable ingestion. This enricher is also compatible with the Elastic.CommonSchema.Serilog package.

Prerequisite

The prerequisite for this to work is a configured Elastic APM Agent. If the agent is not configured the enricher won't add anything to the logs.

Copyright and License

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

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

Downloads by Version

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.